+4 votes
in Operating Systems by (39.4k 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

+4 votes
by (51.8k points)
selected by
Best answer

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