+4 votes
in Operating Systems by (9.6k points)
I want to remove the header from a file and keep the remaining records. Which Linux command should I use to delete the header of a file?

1 Answer

+2 votes
by (11.1k points)
edited by

To delete any row from a file, you can use the 'sed' command with 'd' and '-i' options.

'-i' - Edit files in place

'd' -  Delete pattern space 

You need to give the line number with 'd' to delete that line. E.g. '1d' will delete the first line, '2d' will delete the second line, and so on. 

I have a text file with the following data and using 'sed', I will delete its header i.e. first row.

name    age     salary

aaa     23      2000

bbb     24      8721

ccc     27      5672

ddd     56      323

eee     34      9821

fff     28      4322


sed -i '1d' testfile.txt