[RndTbl] Command line challenge: trim garbage from start and end of a file.

Sean Walberg sean at ertw.com
Wed Nov 10 11:05:11 CST 2010


Oh, and good glaven, there is a shorter AWK one:

awk '/output start/,/output end/' < infile > outfile

Sean

On Wed, Nov 10, 2010 at 10:55 AM, Sean Walberg <sean at ertw.com> wrote:

> OTTOMH:
>
> perl -n -e 'BEGIN {$state = 0} $state = 1 if ($state == 0 and /output
> start/); $state = 2 if ($state == 1 and /output end/)  ; print if ($state ==
> 1)' < infile > outfile
>
> I'll bet there's a shorter AWK version though.
>
> Sean
>
> On Wed, Nov 10, 2010 at 10:51 AM, John Lange <john at johnlange.ca> wrote:
>
>> I have files with the following structure:
>>
>> garbage
>> garbage
>> garbage
>> output start
>> .. good data
>> .. good data
>> .. good data
>> .. good data
>> output end
>> garbage
>> garbage
>> garbage
>>
>> How can I extract the good data from the file trimming the garbage
>> from the beginning and end?
>>
>> The following works just fine but it's dirty because I don't like the
>> fact that I have to pick an arbitrarily large number for the "before"
>> and "after" values.
>>
>> grep -A 999999 "output start" <infile> | grep -B 999999 "output end" >
>> newfile
>>
>> Can anyone come up with something more elegant?
>>
>> --
>> John Lange
>> www.johnlange.ca
>> _______________________________________________
>> Roundtable mailing list
>> Roundtable at muug.mb.ca
>> http://www.muug.mb.ca/mailman/listinfo/roundtable
>>
>
>
>
> --
> Sean Walberg <sean at ertw.com>    http://ertw.com/
>



-- 
Sean Walberg <sean at ertw.com>    http://ertw.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.muug.mb.ca/pipermail/roundtable/attachments/20101110/2a07ddc4/attachment.html 


More information about the Roundtable mailing list