[GLLUG] Shell Scripting Question
Hampton, Rodney
rodney.hampton@jnli.com
Tue, 11 Mar 2003 11:33:16 -0500
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_001_01C2E7EB.EAFCC4C0
Content-Type: text/plain;
charset="iso-8859-1"
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
-----Original Message-----
From: Melson, Paul [mailto:PMelson@sequoianet.com]
Sent: Tuesday, March 11, 2003 10:52 AM
To: linux-user@egr.msu.edu
Subject: [GLLUG] Shell Scripting Question
I recently discovered a bug (?) in a script that I'm using to process log
files from a piece of software that we use. The log file is a
separated-value text file, and the field separator is a pipe '|'. In order
to extract the data I want and drop it into an HTML table, I am using awk in
the following manner:
cat logfile | awk -F\| '{print("<tr><td>",$2,"</td><td>",$5,"</td></tr>")}'
>> output.html
There are only five fields in this file, and I only want to look at fields 2
and 5. The problem arises when, on occasion, field 5 contains a '|'
character, and awk interprets this as a field separator. There is no way to
change the separator before the log file is generated. If the pipe in field
5 is escaped '\|' then awk includes it in field 5. The problem is how to
search and replace only the contents of field 5 for '|' and replace it with
'\|'. Any help would be greatly appreciated.
Thanks,
PaulM
_______________________________________________
linux-user mailing list
linux-user@egr.msu.edu
http://www.egr.msu.edu/mailman/listinfo/linux-user
------_=_NextPart_001_01C2E7EB.EAFCC4C0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2654.45">
<TITLE>RE: [GLLUG] Shell Scripting Question</TITLE>
</HEAD>
<BODY>
<P><FONT SIZE=3D2>Convert your pipes to colons first</FONT>
</P>
<P><FONT SIZE=3D2>cat logfile|sed -e 's/\|/:/g'| awk -F\| =
'{print("<tr><td>",$2,"</td><td>&=
quot;,$5,"</td></tr>")}' >> =
output.html</FONT>
</P>
<P><FONT SIZE=3D2>Rodney Hampton</FONT>
<BR><FONT SIZE=3D2>-----Original Message-----</FONT>
<BR><FONT SIZE=3D2>From: Melson, Paul [<A =
HREF=3D"mailto:PMelson@sequoianet.com">mailto:PMelson@sequoianet.com</A>=
]</FONT>
<BR><FONT SIZE=3D2>Sent: Tuesday, March 11, 2003 10:52 AM</FONT>
<BR><FONT SIZE=3D2>To: linux-user@egr.msu.edu</FONT>
<BR><FONT SIZE=3D2>Subject: [GLLUG] Shell Scripting Question</FONT>
</P>
<BR>
<P><FONT SIZE=3D2>I recently discovered a bug (?) in a script that I'm =
using to process log files from a piece of software that we use. =
The log file is a separated-value text file, and the field separator is =
a pipe '|'. In order to extract the data I want and drop it into =
an HTML table, I am using awk in the following manner:</FONT></P>
<P><FONT SIZE=3D2>cat logfile | awk -F\| =
'{print("<tr><td>",$2,"</td><td>&=
quot;,$5,"</td></tr>")}' >> =
output.html</FONT>
</P>
<P><FONT SIZE=3D2>There are only five fields in this file, and I only =
want to look at fields 2 and 5. The problem arises when, on =
occasion, field 5 contains a '|' character, and awk interprets this as =
a field separator. There is no way to change the separator before =
the log file is generated. If the pipe in field 5 is escaped '\|' =
then awk includes it in field 5. The problem is how to search and =
replace only the contents of field 5 for '|' and replace it with =
'\|'. Any help would be greatly appreciated.</FONT></P>
<P><FONT SIZE=3D2>Thanks,</FONT>
<BR><FONT SIZE=3D2>PaulM </FONT>
</P>
<P><FONT =
SIZE=3D2>_______________________________________________</FONT>
<BR><FONT SIZE=3D2>linux-user mailing list</FONT>
<BR><FONT SIZE=3D2>linux-user@egr.msu.edu</FONT>
<BR><FONT SIZE=3D2><A =
HREF=3D"http://www.egr.msu.edu/mailman/listinfo/linux-user" =
TARGET=3D"_blank">http://www.egr.msu.edu/mailman/listinfo/linux-user</A>=
</FONT>
</P>
</BODY>
</HTML>
------_=_NextPart_001_01C2E7EB.EAFCC4C0--