A scripting question (harder than I thought)

Walter Dnes waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org
Thu Mar 4 06:09:00 UTC 2004


On Sat, Feb 28, 2004 at 10:09:13PM -0500, William Park wrote
> 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

  WOW!  Anyhow, here's a solution I came up with, which builds on your
previous reply...

#!/bin/bash
sed -n "{
: loop
N
s/\n\(.\)/ \1/
t loop
}
P" ${1}

  I will have to read up on "while read line; do".  I had really wanted
to do this as a shell script, but couldn't figure out how to step through
an input file one line at a time.

-- 
Walter Dnes <waltdnes-SLHPyeZ9y/tg9hUCZPvPmw at public.gmane.org>
Email users are divided into two classes;
1) Those who have effective spam-blocking
2) Those who wish they did
--
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