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

Gilles Detillieux grdetil at scrc.umanitoba.ca
Wed Nov 10 11:13:28 CST 2010


sed '1,/^output start/d; /^output end/,$d' < infile > newfile

On 11/10/2010 10:51 AM, John Lange 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?
> 

-- 
Gilles R. Detillieux              E-mail: <grdetil at scrc.umanitoba.ca>
Spinal Cord Research Centre       WWW:    http://www.scrc.umanitoba.ca/
Dept. Physiology, U. of Manitoba  Winnipeg, MB  R3E 0J9  (Canada)


More information about the Roundtable mailing list