I am trying to write a bash script to use sed to delete some lines of a file. The line numbers are stored in another file in reverse order.
The command I am trying to do is the following:
sed -e '{lineNumber}d' ./file.txt
This is what I have so far but it’s not working
while read -r line
do
sed -e "/${line}d" ./file.txt
done < ./lineNum.txt
I am getting the following error:
sed: -e expression #1, char 4: unterminated address regex
This works (I think your problem was to use -e); but it’s not efficient. It may be better to pass multiple lines at a time to sed, to avoid reading and writing the file once per line. E.g., you could transform linenum.txt into something like “6 d;2 d;1 d;” and then pass it to sed for one scoop processing.