Os X 10.9 using sed to delete multiple lines in multiple files

212 Views Asked by At
  • I use terminal in Os X 10.9;
  • I want to delete the same lines in multiple files in the same directory;
  • The file in the directory are named 1.txt 2.txt 3.txt etc. (170 files);
  • The purpose is to delete all the lines except 156 to 698 in every file;
  • The command look like this:

find . -type f -name "*.txt" | xargs sed -i '156,698!d'

Doesn't work except for the first file ? What is the best way to do this ?

Thanks

1

There are 1 best solutions below

0
On

You can use the -I option with xargs and do something like this:

find . -type f -name "*.txt" | xargs -I {} sed -i '156,698!d' {}