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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

awk help

Status
Not open for further replies.

wbe303

MIS
Nov 8, 2007
10
US
I Have this output

paeq45:27502
112.26.259.35
20502
tcp
tcp
active
watp45:23564
157.72.135.35
40204
tcp
tcp
active
rupp47:20225
135.42.224.37
10605
tcp
tcp
active

The only thing that is constant is that the FIRST record (element) contains a ":"

Want output like this

paeq45:27502,112.26.259.35,20502,tcp,tcp,active
watp45:23564,157.72.135.35,40204,tcp,tcp,active
rupp47:20225,135.42.224.37,10605,tcp,tcp,active
 
Here's some pseudo code.

Open file
:start
flag for target line = 0
match line where line contains colon and set flag for target line
getline through file till next target line found, appending each line found to target with desired delimiters
reset flag
set target to current record && goto start
 
[tt]

Perhaps this ..

# awk 'BEGIN {FS="," ; RS="\n" } { printf("%s%s", $0,ORS=(FNR%6)?FS:RS) }' data

paeq45:27502,112.26.259.35,20502,tcp,tcp,active
watp45:23564,157.72.135.35,40204,tcp,tcp,active
rupp47:20225,135.42.224.37,10605,tcp,tcp,active



[/tt]
 
Ranjit

I am running Sun 5.8 and get this error msg.

awk: syntax error near line 1
awk: illegal statement near line 1

Thanks

awk 'BEGIN {FS="," ; RS="\n" } { printf("%s%s", $0,ORS=(FNR%6)?FS:RS) }' foo1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top