0

I would like to use sed instead of grep because of set -e presence in my shell script.

I am using grep -v -f -F to filter some patterns from a file file1.txt like,

grep -v -f -F file.txt data.txt > filtereddata.txt

This will filter the data which is not matching the pattern in file.txt. I need to do this using sed. I was able to find invert match using '//p!' in sed but could not find combination of -f with '//p!'.

Is above grep command possible using sed with equivalent or better performance?

Nachiket Kate
  • 8,473
  • 2
  • 27
  • 45
  • 3
    You can keep a failed `grep` from bombing out your script due to `set -e` by putting `|| true` on the end of the command. This also works for any other command whose exit code should not abort the script. – Mark Reed Nov 12 '15 at 19:25
  • 1
    I think @MarkReed's solution is the right one. Also, if you plan on using `set -e`, you will want to read the Bash FAQ: [Why doesn't set -e (or set -o errexit, or trap ERR) do what I expected?](http://mywiki.wooledge.org/BashFAQ/105). – John1024 Nov 12 '15 at 19:31
  • I am working on doing it using grep ... || true but meanwhile I thought of using it with sed. Can you please provide the same output using sed command? – Nachiket Kate Nov 12 '15 at 19:40
  • 1
    `sed` doesn't have a non-regex match option – anubhava Nov 12 '15 at 19:44
  • This user's [earlier question](http://stackoverflow.com/q/33679169/258523) is useful as background here (where I discuss `set -e` workarounds and that Bash FAQ entry). – Etan Reisner Nov 12 '15 at 20:13

0 Answers0