I have a hack script that is checking for some entries in a vary large log file. It is a mix of perl and bash - it works fine - the script gets what it needs to get. The only problem is the formatting "$chdk_subscription" I have tried to delimit the output by a keyword 'STATS' and 'added'. These two words are at the beginning and the end of each line that I want to read.
#!/bin/bash
pid_foo_process=$(pgrep foo_process)
check_primary=$(grep $1 /data/foo_process-0210.$pid_foo_process.log | perl -nle 'print /(primary book \w+:\w+)/ ')
check_primary_symbol=$(grep $1 /data/foo_process-0210.$pid_foo_process.log | perl -nle 'print /primary book (\w+:\w+)/ ')
chdk_subscription=$(grep $1 /data/foo_process-0210.$pid_foo_process.log | perl -nle 'print if /(subscription for \w+:\w+.*)/ ')
echo $check_primary
echo $check_primary_symbol
IFS="STAT"
while read line
echo $line
done < echo $chdk_subscription
Breaking up "$chdk_subscription" by 'IFS' does not seem to work
echo $chdk_subscription| awk -F"STATS" '{print $0}'
using awk is not working either -- each time it comes out as one big line with no newlines.
STATS 10/15 08:03:09.391048 32978 (0)SB: subscription for APA:T added STATS 10/15 08:03:09.391164 32978 (0)SB: subscription for APA:P added STATS 10/15 08:03:09.391226 32978 (0)SB: subscription for APA:Z added STATS 10/15 08:03:09.391537 32978 (0)SB: subscription for APA:n added STATS 10/15 08:03:09.391599 32978 (0)SB: subscription for APA:A added STATS 10/15 08:03:09.391686 32978 (0)SB: subscription for APA:a added STATS 10/15 08:03:09.391756 32978 (0)SB: subscription for APA:K added STATS 10/15 08:03:09.391818 32978 (0)SB: subscription for APA:J added STATS 10/15 09:38:12.826928 32978 (0)SB: subscription for APA:N, XNYSAPA:3 added
I want something like this that I can read.
STATS 10/15 08:03:09.391048 32978 (0)SB: subscription for APA:T added
STATS 10/15 08:03:09.391164 32978 (0)SB: subscription for APA:P added
STATS 10/15 08:03:09.391226 32978 (0)SB: subscription for APA:Z added
STATS 10/15 08:03:09.391537 32978 (0)SB: subscription for APA:n added
STATS 10/15 08:03:09.391599 32978 (0)SB: subscription for APA:A added
STATS 10/15 08:03:09.391686 32978 (0)SB: subscription for APA:a added
STATS 10/15 08:03:09.391756 32978 (0)SB: subscription for APA:K added
STATS 10/15 08:03:09.391818 32978 (0)SB: subscription for APA:J added
STATS 10/15 09:38:12.826928 32978 (0)SB: subscription for APA:N, XNYSAPA:3 added
echo $lineIS NOT THE SAME ASecho "$line"; the former will change newlines to spaces, expand glob expressions, and do all kinds of other messing with your formatting you almost certainly don't want.\nchanged from two characters into a single newline), useread -r, not bareread.