Is there a simple way to remove the same line of text from a folder full of text documents at the command line?
To delete a line, we'll use the sed “d” command. Note that you have to declare which line to delete. Otherwise, sed will delete all the lines.
The sed command can remove the lines of any range. For this, we just have to enter 'minimum' and 'maximum' line numbers. In this example, we will remove the lines ranging from 4 to 7 numbers. After removing these ranges of lines, our file will look like this.
multiple-files-remove-prefix.mdfor file in prefix*; do mv "$file" "${file#prefix}"; done; The for loop iterates over all files with the prefix. The do removes from all those files iterated over the prefix.
If your version of sed allows the -i.bak
flag (edit in place):
sed -i.bak '/line of text/d' *
If not, simply put it in a bash loop:
for file in *.txt do sed '/line of text/d' "$file" > "$file".new_file.txt done
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With