Hi,
I'm writing an awk script to parse an input file. The input file has many fields about a user. There is one field I need to break up into pieces.
...
givenName: John
sn: Smith
st: CA
postalCode: 90210
departmentNumber: 999-IT Department
...
I am already calling the script with awk -F": ", so I need to find a way to print the single field 3 different ways.
I think I need to use split or sub, but I'm not sure what the best way to achieve it is.
Desired output is:
John,Smith,CA,90210,999,IT Department,999-IT Department
In my awk script I was able to extract the first part like this:
/departmentNumber/{departmentnumber = index($2, "-") ? substr($2, 1, index($2, "-")-1) : $2; departmentname = ??; fulldepartmentname = $2}
In that same line I need to set the other 2 variables.
Any help would be greatly appreciated.
Thanks,
John
I'm writing an awk script to parse an input file. The input file has many fields about a user. There is one field I need to break up into pieces.
...
givenName: John
sn: Smith
st: CA
postalCode: 90210
departmentNumber: 999-IT Department
...
I am already calling the script with awk -F": ", so I need to find a way to print the single field 3 different ways.
I think I need to use split or sub, but I'm not sure what the best way to achieve it is.
Desired output is:
John,Smith,CA,90210,999,IT Department,999-IT Department
In my awk script I was able to extract the first part like this:
/departmentNumber/{departmentnumber = index($2, "-") ? substr($2, 1, index($2, "-")-1) : $2; departmentname = ??; fulldepartmentname = $2}
In that same line I need to set the other 2 variables.
Any help would be greatly appreciated.
Thanks,
John