A scripting question (harder than I thought)
William Park
opengeometry-FFYn/CNdgSA at public.gmane.org
Sun Feb 29 03:09:13 UTC 2004
On Sat, Feb 28, 2004 at 08:02:53PM -0500, Walter Dnes wrote:
> 1) The "anchor line" begins with regex "^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)
> (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) "
> and ends with "]"
>
> 2) Followed N lines (N > 0) of text, which do not match rule 1.
>
> 3) Followed by one zero-length line
>
> I think that a script-based approach would work like so
>
> - find a line that does *NOT* match rule 1
> - join it to the previous line
(3) is better pattern than (1) or (2); that is, every log is separated
by an empty line. Now, if I read you right, you want to join
multi-lines into a single-line for each log. In that case,
1. awk -v RS='' '{gsub("\n", ""); print}'
2. csplit logfile '/^$/' '{*}'
for i in xx*; do
tr -d '\n' < $i
done
3. while read line; do
case $line in
'') echo ;;
*) echo -n "$line" ;;
esac
done
If you need to match "Mon Jan ...", then solutions are slightly
different, because you have explicit beginning and ending. From top of
my head,
4. print=no
while read line; do
case $line in
Mon*|Tue*|Wed*|Thu*|Fri*|Sat*|Sun*) print=yes ;;
'') print=no ;;
esac
case $print in
yes) echo -n "$line" ;;
no) echo "$line" ;;
esac
done
5. awk '
/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/ {ORS=""}
/^$/ {ORS="\n"}
{print}
'
6. echo -e 'g/^(Mon|Tue|Wed|Thu|Fri|Sat|Sun)/.,/^$/j\nwq' | ed
--
William Park, Open Geometry Consulting, <opengeometry-FFYn/CNdgSA at public.gmane.org>
Linux solution for data management and processing.
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list