I have a file called list.txt and its content is as follows:


(The rest is omitted)

I want to do something like the pseudo code:

point to first line of list.txt;
while (list.txt not reaching end of file)
    get string from line;
    find -name 'string';
    if (find)
        delete first 7 lines in file;
    advance one line;

I believe the combination of find, xargs and sed can achieve this.

  • what if a file found that it was containing less or equal to 7 lines? Commented Jun 18, 2020 at 7:44
  • @αғsнιη I tested sed to delete first 7 lines in a file that containing less than 7 lines. The outcome is that it become empty file. That's what I want it to be.
    – Andy Lin
    Commented Jun 18, 2020 at 8:13

1 Answer 1


You can try something like

$ xargs -a list.txt -I myfilename find . -name myfilename -exec sed 1,7d '{}' \;
  • xargs reads the name of the files in list.txt and replaces the myfilename pattern with the name of the file read in the find command
  • find will find your file and pass it to sed wich delete the first 7 lines (or empty the file if there is less than 7 lines)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .