-2
  1. I have a file file1 which contains various strings. These strings have to be used with regular expression.
  2. I have a another file which will be updated in realtime. tail -f <filename> will provide the continuous output.

  3. My requirement is to skip the strings present in file1 and show the rest of output in file2.

For example: file1 has the content below

Result of operation: got a 2 bytes
49.53.4F.30.31.36.30.30.30.30.31.35.30.32.31.30
Processing Event

Note: to match line 2 in file1, I have to use a regular expression.

File2 has content that will be file1 + X. So, in my output only X (the extra lines) should be displayed.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
swwapnil
  • 1
  • 4
  • possible duplicate of [Remove Lines from File which appear in another File](http://stackoverflow.com/questions/4366533/remove-lines-from-file-which-appear-in-another-file) – tripleee Feb 12 '15 at 10:24
  • Actually http://stackoverflow.com/questions/4366533/remove-lines-from-file-which-appear-in-another-file is a better duplicate. Sorry for the mess. – tripleee Feb 12 '15 at 10:25

1 Answers1

1

To display additions to file2 in real time while skipping any lines which match a regular expression in file1, use:

tail -f file2 | grep -vf file1
John1024
  • 109,961
  • 14
  • 137
  • 171
  • What is I have file3,file4.. in addition to file2 and I want to show the common ouptut. please help – swwapnil Feb 12 '15 at 07:30
  • 1
    The question, as it currently is written, says nothing about a `file3` or a `file4`. What does it mean that you want "to show the common output"? Do you only want to display lines from `file2` if they are also in `file3` and also in `file4`? Or what? – John1024 Feb 12 '15 at 07:37
  • yes. file1 has list of master strings to be checked. file2,file3,file4 can contain strings from file1. I want to list everything unmatched output from file2,3,4 into single one. sorry, did not give you this info earler. – swwapnil Feb 12 '15 at 07:42
  • Also to add to this answer, if you want to pass the grep output to another piped command, you may likely need to add `--line-buffered` option to `grep` command. – anishsane Feb 12 '15 at 07:48
  • Hello anish, Can you explain me more on how to add a --line-buffered option ? an example would be help a lot – swwapnil Feb 12 '15 at 07:53