In a folder, I have number of files that are in .dat extension format (it is originally .xvg format but have changed to .dat format to plot all other graphs in a single plot) which contains the values along with the some written headings etc., as :

 # Grace project file


@version 50125
@page size 792, 612

@page scroll 5%

@page inout 5%

@link page off

@map font 8 to "Courier", "Courier"

@map font 10 to "Courier-Bold", "Courier-Bold"

@map font 11 to "Courier-BoldOblique", "Courier-BoldOblique"

@map font 9 to "Courier-Oblique", "Courier-Oblique"

@map font 4 to "Helvetica", "Helvetica"

@map font 6 to "Helvetica-Bold", "Helvetica-Bold"

@map font 7 to "Helvetica-BoldOblique", "Helvetica-BoldOblique"

@map font 5 to "Helvetica-Oblique", "Helvetica-Oblique"





@    s0 errorbar riser linestyle 1

@    s0 errorbar riser clip off

@    s0 errorbar riser clip length 0.100000

@    s0 comment "rdf_CaNm.xvg"

@    s0 legend  "N1"

@target G0.S0

@type xy

0 0

0.002 0

0.004 0

ie., there are 327 lines from #Grace project file(being line one) --> @type xy(being line 327) and then the 0 0 is the 328th line, 0.002 0 is the 329th line etc.

How can I delete all the first 327 lines in all the files of .dat format containing in the folder (yes all those .dat files have first 327 lines as stated above) through the command in terminal?

  • with the simple addition of sed ... *.dat – Jeff Schaller Jul 13 '17 at 19:27

To delete a number of lines from one file, you will do:

sed -i -e 1,327d file.dat

Here you do it with --in-place (-i) which is change the file, and 1,327d means delete from line one to 327.

To delete the first 327 lines from all files name *.dat in this directory and below, use find:

find -name '*.dat' -exec sed -i -e 1,327d {} \;
| improve this answer | |
  • 1
    or, if there are not millions of such files, sed -i -e 1,327d *.dat – Jeff Schaller Jul 13 '17 at 19:27
  • add the regular-file clause in find to make it more accurate and sed can handle more than one file: find . -type f -name \*.dat -exec sed -si -e 1,327d {} + – user218374 Jul 14 '17 at 7:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.