Reputation: 33
I'm trying to use sed to clean a list. Any lines appearing in $salvation should be removed from the already set $naughtyList.
I have;
$ echo "$naughtyList"
ONE/1/one
TWO/2/two
THREE/3/three
FOUR/4/four
FIVE/5/five
and;
$ echo "$salvation"
TWO/2/two
FOUR/4/four
The problem is the slash characters. I can't escape them when trying;
for line in $(echo $salvation); do
naughtyList=$(echo $naughtyList | sed "/$line/d")
done
sed: -e expression #1, char 6: unknown command: `2'
sed: -e expression #1, char 7: unknown command: `4'
Is there a way to pass $line, or do I have to modify the input patterns?
Thanks in advance.
Upvotes: 1
Views: 53
Reputation: 785196
Better to use grep -f
here with process substitution:
grep -vFf <(echo "$salvation") <(echo "$naughtyList")
ONE/1/one
THREE/3/three
FIVE/5/five
To update naughtyList
variable, use:
naughtyList=$(grep -vFf <(echo "$salvation") <(echo "$naughtyList"))
Upvotes: 1