linux - Unix (ksh) script to read file, parse and output certain columns only -


i have input file looks this:

"level1","cn=app_group_abc,ou=dept,dc=net","uid=a123456,ou=person,dc=net" "level1","cn=app_group_def,ou=dept,dc=net","uid=a123456,ou=person,dc=net" "level1","cn=app_group_abc,ou=dept,dc=net","uid=a567890,ou=person,dc=net" 

i want read each line, parse , output this:

a123456,abc a123456,def a567890,abc 

in other words, retrieve user id "uid=" , identifier "cn=app_group_". repeat each input record, writing new output file.

note column positions aren't fixed, can't rely on positions, guessing have search "uid=" string , somehow use position maybe?

any appreciated.

you can use awk split in columns, split ',' , split =, , grab result. can awk -f, '{ print $5}' | awk -f= '{print $2}'

take @ line looking @ example provided:

cat file  | awk -f, '{ print $5}' | awk -f= '{print $2}' a123456 a123456 a567890 

Comments

Popular posts from this blog

tcpdump - How to check if server received packet (acknowledged) -