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!

Help with AWK File Processing 1

Status
Not open for further replies.

gaka1108

Technical User
Feb 1, 2016
5
GB
Hi All,

I have an input file in linux with the following entries:

X:1,2,3,4
Y:5,6,7,8
...and so on

I require an output like below:

X:1
X:2
X:3
X:4
Y:5
Y:6
Y:7
Y:8

Could someone please provide a solution to this?

Regards,
Gaurav
 
Hi

Assuming there are no other colons ( : ) and commas ( , ) then the field delimiters :
Code:
master # awk -F '[:,]' '[teal]{[/teal][b]for[/b][teal]([/teal][navy]i[/navy][teal]=[/teal][purple]2[/purple][teal];[/teal][navy]i[/navy][teal]<=[/teal]NF[teal];[/teal][navy]i[/navy][teal]++)[/teal][b]print[/b][navy]$1[/navy][i][green]":"[/green][/i][navy]$i[/navy][teal]}[/teal]' /path/to/input
X:1
X:2
X:3
X:4
Y:5
Y:6
Y:7
Y:8

Feherke.
feherke.ga
 
Super! Worked like a charm. Thank you so much!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top