Unix help- sed or awk

July 5, 2009 at 21:07:23
Specs: Linux
I have a file of the following format.

2,
212.1.1.1
213.2.2.2 0.0.0.32
8,
10.1.2.3
172.4.5.212
172.212.212.212

The output should be as shown below. So, Whereever, there is a comma in a line, the line contents should be prefixed to the next few lines until the the next line with comma is seen.

2 212.1.1.1
2 213.2.2.2 0.0.0.32
8 10.1.2.3
8 172.4.5.212
8 172.212.212.212


See More: Unix help- sed or awk

Report •


#1
July 5, 2009 at 21:41:51
awk -F"," '/,$/{s=$1;next}{ print s,$0}' file

GNU win32 packages | Gawk


Report •

#2
July 6, 2009 at 12:23:45
Thank you. That worked.

Report •

Related Solutions


Ask Question