2

I would like to delete the first 40 lines of a good number of ASCII files and save the ASCII files without those 40 lines

I'm working under OSX High Sierra, realized that the -i option in sed was not working unless I create a backup file, so I tried using this command:

sed -i'backup' -e '1,40d' *.txt 

It however only modifies and deletes the first 40 lines in my first file (alphabetically), but not the others.

How can I edit multiple files with just one command?

Thanks

2
  • Possible duplicate of Change multiple files Commented Feb 19, 2019 at 2:23
  • 2
    Won't work on OSX Sierra. See this answer. Commented Feb 19, 2019 at 2:24

1 Answer 1

0

You can use the following command that will

  • look in the current folder
  • ignore sub folder
  • take only into account files whose filenames end with '*.txt'
  • before executing the sed command.

Command:

 find . -maxdepth 1 -type f -name '*.txt' -exec sed -i 'backup' -e '1,40d' {} \; 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.