Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$ tail -f /logs/filename.log | awk '!(/list)'

I am able to run this command in GNU Linux flavour

But when I written in a script it is not working.


variable="/logs/filename.log | awk '!(/list)'" 
tail -f $var

Getting the error as

tail: cannot open `|' for reading: No such file or directory
tail: cannot open `grep' for reading: No such file or directory
tail: cannot open `list' for reading: No such file or directory

How is need to work on this? Can anyone guide on this?

share|improve this question
For first, I see no way the original one could work as the awk code has syntax error. – manatwork Apr 27 '12 at 12:44
What the others are saying is that you can't put a pipe or other shell special characters into a string and then hope the shell can read your mind. You can however use eval, but that's generally not advised. – glenn jackman Apr 27 '12 at 15:38

Your code is broken in a couple of ways...

  • You define a variable with the name variable, then call it with the name var. That won't work.

  • I can't make out what you were trying to accomplish with the variable in the first place because the quoting is so screwy. The interpreter will have the more problems than I did ;-) In effect, you are sending a string that looks like a set of commands including a pipeline -- but since they are inside of a quoted string as an argument to another command, they will just come across as so many characters in a text blob as an argument. Not something the interpreter will touch.

Perhaps you want something like this in your test.ksh file:

tail -f $log_file | awk '!(/list)'

Or even this which you would run with a command like ./test.ksh /logs/filename.log:

tail -f $1 | awk '!(/list)'
share|improve this answer

You wrote 2 different things.

In the shell, you stated that the output of tail -f is redirected to awk

In your script, you stated that tail -f should read data from the files named "/logs/filename.log", "|", "awk" and "!(/list)"

You want to write this in your script file:

tail -f $variable | awk '!(/list)'
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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