Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK Scripting Loop

Status
Not open for further replies.

gaka1108

Technical User
Feb 1, 2016
5
GB
I have file like this:

Code:
root:x:0::192.168.164.164
bin:x:1:bin,daemon:192.168.164.164
daemon:x:2:bin,daemon:192.168.164.164


I wish to have a script which transforms the above into:

Code:
root;0;;192.168.164.164
bin;1;bin;192.168.164.164
bin;1;daemon;192.168.164.164
daemon;2;bin;192.168.164.164
daemon;2;daemon;192.168.164.164

 
It looks like you want to use : as your FS, Field Separator and are only interested in $1,$3, and $5 and you want to create multiple records when $4 is parsed by comma. Is that a correct interpretation of the requirements?


==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
what have you tried so far?

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Here's a little something to get you started (untested)

awk FS=: '{if (index($4,")>0) print $1 $2 substr($4,1,index($4,",")-1) substr($4,index($0,",")) $5; else print $1 $2 $4 $5;}' /path/to/inputfile > /path/to/outputfile

==================================
advanced cognitive capabilities and other marketing buzzwords explained with sarcastic simplicity


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top