[GLLUG] Shell Scripting Question

Melson, Paul PMelson@sequoianet.com
Tue, 11 Mar 2003 10:51:39 -0500


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