I have a list of packagenames and want to delete some of those with sed
echo "package1 package2 package24 package44 package66 package12345" > benoetigte_pakete.list
How can I delete some of those that are in another list?
dellist="package24|package66"
I tried
cat benoetigte_pakete.list | sed "s/(package24|package66)//"
but that doesn't work.
In sed regexps you have to escape (, |, and ).
You also need to use the g modifier so it replaces all matches on the line, not just the first match.
dellist="package24|package66"
# escape the pipes
dellist=${dellist//|/\\|}
sed "s/\b\($dellist\)\b//g" benoietigte_packete.list
I've added the \b so it only matches whole words.
Depending on the version of sed you have, you can also use the -E or -r options to use extended regular expressions.
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