1

I was wondering if something like this exist:

tail -f file1 | grep "hello" > fileHello | grep "bye" > fileBye | grep "etc" > fileEtc
echo b1bla >> file1  
echo b2hello >> file1
echo b3bye >> file1
echo b4hellobye >> file1
echo b5etc >> file1
echo b6byeetc >> file1

That will make that result :

file1:

b1bla
b2hello
b3bye
b4hellobye
b5etc
b6byeetc

fileHello:

b2hello
b4hellobye

fileBye:

b3bye
b4hellobye
b6byeetc

fileEtc:

b5etc
b6byeetc

Thanks!

1

2 Answers 2

2

Use tee with process substitution:

tail -f file1 | tee >(exec grep "hello" > fileHello) >(exec grep "bye" > fileBye) | grep "etc" > fileEtc
1

This works, but be aware that piping tail -f is likely to cause some unexpected buffering issues.

tail -f file1 |
 awk '/hello/ { print > "fileHello"}
   /bye/ { print > "fileBye"}
   /etc/ { print > "fileEtc"}' 
2
  • it's working if i cat file1, but not with tail... i dont want to have to run cat... i want the command to run in background... is it possiible?
    – frank
    Aug 11, 2014 at 20:31
  • tail does not run in the background. When you say "not with tail", I suspect you mean that the buffering issues are causing it to appear to not work. You can try using stdbuf to tweak the buffering, but only if available. Aug 12, 2014 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.