I'm trying to clean up long-cluttered-filename.txt by deleting the lines that match the strings in my delete-these-lines.txt...
$ cat delete-these-lines.txt
context
platform
server
civicrm
site_enabled
client
redirection
cron_key
^\s*[0-9]*\s
alias
profile
install
ssl_
address
...and with a simple for loop I can iterate through the lines of that file like so:
$ for l in delete-these-lines.txt; do cat $l; done
context
platform
server
civicrm
site_enabled
client
redirection
cron_key
^\s*[0-9]*\s
alias
profile
install
ssl_
address
but when I try to substitute cat for sed it doesn't work. Neither of these work:
for l in delete-these-lines.txt; do sed -i "/$l/d" long-cluttered-filename.txt; done
for l in delete-these-lines.txt; do sed -i '/"$l"/d' long-cluttered-filename.txt; done
Is this a problem with the $l variable being interpolated? Is this a limitation of for loops?
I see answers like loop sed to delete line with strings provided in a list of strings from a text file and Read line from file then delete that use while loops with read but I'd prefer to use a for loop if it's possible, and if it's not possible I'd like to know why.
for l in delete-these-lines.txt ...loops over the filename, once. You presumably wantfor l in $(<delete-these-lines.txt) ...orfor l in $(cat delete-these-lines.txt) ...to loop over the file's contents. But it's a bad idea. – steeldriver Feb 13 '20 at 18:10forloop in this context. – steeldriver Feb 13 '20 at 18:44delete-these-lines.txtcontain patterns or strings? That is, should^\s*[0-9]*\smatch that string literally, or is that a PCRE regular expression? – Kusalananda Feb 13 '20 at 23:00^\s*[0-9]*\sis a regex pattern (I'm not sure about PCRE though), not a literal string. – alec Feb 14 '20 at 00:26forloop as I am to figure out if and how it's possible; thegrep -v -f....option looks great in how it functions, but I'm trying learn about how these loops work... and your comment on the distinction between looping over the filename vs the file contents was helpful :) – alec Feb 14 '20 at 00:41