I want to delete text from multiple files. It could be from 10 to 1000 files, so deleting it by hand is too much work. I found a couple of SO questions, such as: Delete specific lines in multiple Text Files with freeware App? but none of them helped
To do find and replace, I could write a perl command, but it lacks options. For example, I want to delete the first four lines in all files. Does anyone know a solution? Or maybe an app? I would prefer something without VBScript.
sed(1)
or awk(1)
would be great for this job. For example, to delete the first 4 lines of all of the .txt
files in the current directory:
sed -i~ 1,4d *.txt
This will delete the first 4 lines of all .txt
files anywhere in a subdirectory of the current directory:
find . -type f -iname \*.txt -exec sed -i~ 1,4d '{}' +