Remove extra header lines from file, except for the first line

You can use

sed '2,${/ID/d;}'

This will delete lines with ID starting from line 2.


header=$(head -n 1 input)
(printf "%s\n" "$header";
 grep -vFxe "$header" input
) > output
  1. grab the header line from the input file into a variable
  2. print the header
  3. process the file with grep to omit lines that match the header
  4. capture the output from the above two steps into the output file

For those who do not like curly brackets

sed -e '1n' -e '/^ID/d'
  • n means pass line No.1
  • d delete all matched line(s) that start with ^ID