Mostly Linux & Python syntax notes and hyperlinks.

Thursday, June 10, 2010

Linux: remove header and trailer lines from input file

  • Use "sed '$d' infile > outfile" to remove the first line.
  • Use "sed '1d' infile > outfile" to remove the last line.
$ cat hf.dat
head
one
two
three
foot
$ sed '$d' hf.dat > nofoot
$ cat nofoot
head
one
two
three
$ sed '1d' nofoot > noheadfoot
$ cat noheadfoot
one
two
three
$

No comments:

Post a Comment