1

Ok so let's say I have a file called system.log, inside this file are thousands of lines of log stuff.

Within those lines are a couple of lines I'd like to see.

Jun 20 18:28:54 Wills-MacBook-Pro SpringBoard[75216]: MyApp 
initialized.
Jun 20 18:28:54 Wills-MacBook-Pro SpringBoard[75216]: MyApp error on 
line 2

I'd like to see them in console, but not

Jun 20 18:28:54 Wills-MacBook-Pro SpringBoard[75216]: SomethingElse initialized.

Sort of like a

tail -f system.log (echo if MyApp in line)

Is something like this possible?

gung - Reinstate Monica
  • 11,583
  • 7
  • 60
  • 79
Will
  • 4,942
  • 2
  • 22
  • 47

3 Answers3

1

Yes, simply pipe it through a grep command.

tail -f system.log | grep MyApp
Jedi
  • 3,088
  • 2
  • 28
  • 47
1

In addition to the other answers here, I'd recommend using multitail. It's pretty intuitive.

Here's how I would use it to filter out only the lines of interest and append them to a new logfile

multitail -e "MyApp" system.log

The -e is used for regular expression followed by the criteria.

Furthermore, you can save all your matches to a new file by simply adding the append flag.

multitail -a append_to_new_file.log -e "MyApp" system.log

Here's the man page for more info and you can find more examples here

Anup
  • 99
  • 1
  • 4
0

Within those lines are a couple of lines I'd like to see

Then you shouldn't use tail command since it outputs only the last 10 lines. The soln is

cat system.log | grep MyApp

a simple grep pipelining does the trick.

Akash
  • 939
  • 1
  • 8
  • 27
  • Cat isn't autoupdating like `tail -f` is – Will Jun 22 '17 at 14:15
  • 1
    `tail` does much more than output the last ten lines. OP wants to use [tail following](https://unix.stackexchange.com/questions/18760/how-does-the-tail-commands-f-parameter-work) – Jedi Jun 22 '17 at 14:52
  • @Jedi I know that, the OP doesnt mentions anything about other requirement. – Akash Jun 22 '17 at 19:32
  • @Will very correct, for that we have: https://stackoverflow.com/questions/7161821/how-to-grep-a-continuous-stream – Akash Jun 22 '17 at 19:33