[GLLUG] Shell Scripting Question

Melson, Paul PMelson@sequoianet.com
Tue, 11 Mar 2003 17:22:52 -0500


I think your sed command would change all pipes to colons, and not all of the pipes on any given line of this file would be field separators.  If I were going to substitute another character for pipes as field separators, I would only want to hit the first 4.  

But I like your idea of replacing the field separators, so I'm going to use it.  What I've come up with and am testing right now isn't pretty, but it seems to fix this issue:

cat logfile |sed -e 's/|/\`/4' |sed -e 's/|/\`/3' |sed -e 's/|/\`/2' |sed -e 's/|/\`/1' |sed -e 's/|/\|/g' | awk -F\` '{print("<tr><td>",$2,"</td><td>",$5,"</td></tr>")}'

In a nutshell, it changes the first 4 pipes on the line to backquotes to serve as field separators.  (A quick grep of my raw log files shows no backquotes, so I went with this - most other characters such as dashes, colons, etc. show up in field 5 at one time or another.)  Then it changes the remaining pipes to escaped pipes '\|' so that they don't cause any trouble later on.

Thanks for your help!

PaulM


-----Original Message-----
From: Hampton, Rodney [mailto:rodney.hampton@jnli.com]
Sent: Tuesday, March 11, 2003 11:33 AM
To: Melson, Paul; linux-user@egr.msu.edu
Subject: RE: [GLLUG] Shell Scripting Question


Convert your pipes to colons first 
cat logfile|sed -e 's/\|/:/g'| awk -F\| '{print("<tr><td>",$2,"</td><td>",$5,"</td></tr>")}' >> output.html 
Rodney Hampton