I tried using
ps r > log | wc log but this returns
Ambiguous output redirect..
Can someone explain why and provide another solution?
The pipe symbol ("|") redirects the output of one program to the input of another.
You however use ">" to redirect
wc's output to a file named log AND at the same time want to redirect the output to STDIN of
wc (which won't use it as you provide an input file for
So, you want one of the following (Hint: the latter solution is better as it doesn't create extra files.)
ps r > log ; wc log
BTW: you might want
wc to count lines, so
wc -l in that case.
You are mixing redirection and piping
ps r > log # redirects ps output to a file called log (over writing any contents of log)
What you want is
ps r | wc # this connects the output of ps to the input of wc
If you wanted to use your methodology, then you would need to do the following
ps r > log; wc log
ps redirects its output to a file called log, then the command
wc is run on the file