1) Please use ***
[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do
not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. Thanks.
2)
Don't Read Lines With For! Always use a while+read loop when taking input from a file or other command. It's a
Useless Use Of Cat as well.
3) When you do have to use command substitution,
$(..) is highly recommended over `..`.
4) The logic of the loop is wrong for the purpose described anyway. The '>' redirect will overwrite today3.txt on each iteration of the loop, meaning you'll only ever see the last entry in the final output.
What you'd need to do is re-feed the result of each iteration back into
sed for further processing. You can use sed's -i option to edit it in place.
Code:
cp today2.txt today3.txt
while read -r var ; do
sed -i "s/$var//g" today3.txt
done <today1.txt
But all this is rather inefficient, since you have to run one sed command for every entry. I'd probably do something like this instead.
Code:
sed -f <( sed 's|.*|s/&//g|' today1.txt ) today2.txt >today3.txt
The
sed embedded in the
process substitution converts the contents of today1.txt into a series of
sed expressions. This is then passed to the main
sed process through the
-f "read expressions from a file" argument, which uses it to replace every matching line in today2.txt, with the output going to today3.txt.