scripting - How to remove header and footer records of a flat file using UNIX shell script? -


i having flat file give below. how delete header , footer file using unix shell script , rewrite same file.

9 20050427 header record 0000000 00000 000000000 123456 00 654321 datarecord 0000000 00000 000000000 123456 00 654321 datarecord 0000000 00000 000000000 123456 00 654321 datarecord 0000000 00000 000000000 123456 00 654321 datarecord 6 20050427 trailer record 

thanks, arun

this ugly, seems work, @ least on input:

f='test.txt'; g=`wc -l $f`; h=`echo $g | cut -d ' ' -f1`; head -n $((h-1)) $f | tail -n $((h-2)) 

f name of file. couldn't work out quicker way rid of filename output of wc. should able beat this.

if want rewrite same file, redirect output of command:

f='test.txt'; g=`wc -l $f`; h=`echo $g | cut -d ' ' -f1`; head -n $((h-1)) $f | tail -n $((h-2)) > $f 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -