|
-
awk script with spaces and /
I am trying to transform an LDAP entry that looks like this:
/cn=Printer1/ou=HR/dc=N/A/dc=fabrikam/dc=com
I am using an awk script and am having a bit of trouble so any help is appreciated.
I am specifically trying to escape the "/" in dc=N/A so that it is quoted like dc="N/A". Actually, I would like to quote everything that is between the "=" and the next "/", so it looks like this.
/cn="Printer1"/ou="HR"/dc="N/A"/dc="fabrikam"/dc="com"
Becasue another issue I am having is related to spaces to the right of the "=".
For example:
/cn=Printer1 Building 1/ou=HR/dc=N/A/dc=fabrikam/dc=com
My algorithinm - right now - is to split the parts into an array at the "=". If the array part contains more than one slash quote the whole thing then print the array part out.
Here is what I have so far:
#!/usr/bin/ksh
DN=/cn=Printer1 Building 1/ou=HR/dc=N/A/dc=fabrikam/dc=com
# Get the number of "=" in the DN and add 1 for the last segment
echo $DN|sed 's/\=/ EQUALS /g'|tr ' ' '\012'|sort|uniq -c|grep EQUALS>count
# this needs to be fixed to include # > 9 - works for now
VAL="$(cut -c4 count)"
VAL=$((VAL+1))
echo $DN | awk -v val=$VAL '{split($1, dnstring, "=");
for (i = 1; i <= val; i++)
print dnstring[i]}'
exit 0
As I have said, any help and/or advice is appreciated.
Thanks,
terryb
Similar Threads
-
By bubberz in forum ASP.NET
Replies: 2
Last Post: 08-23-2005, 02:19 PM
-
By Alintex in forum vb.announcements
Replies: 0
Last Post: 12-16-2002, 02:30 AM
-
By Alintex in forum dotnet.announcements
Replies: 0
Last Post: 12-16-2002, 02:30 AM
-
By Chris in forum Database
Replies: 3
Last Post: 08-20-2002, 12:14 AM
-
By Lakshmeenarayana G G in forum Enterprise
Replies: 0
Last Post: 02-05-2002, 08:43 AM
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks