Output to a text file, the results of compound command
How to output to a text file the compound command:
Code:
find -type f -print0 | xargs -0 grep -l "desired text" Code:
> Code:
ls -al /etc > etc.txt Code:
ls -al /etc/inittab >> etc.txt Thanks in advance! |
What goes wrong with this?
Code:
find -type f -print0 | xargs -0 grep -l "desired text" > output.txt |
Your compound command works fine for me, using shell redirection:
Code:
root@reactor: find ./ -type f -print0 | xargs -0 grep -l "Kalli" |
I'll post a short testcase here, because GrapefruiTgirl seems to agree with me, that there's nothing wrong. This is a tad shorter than what the OP posted, but nevertheless..
First, let's set up some files. Two that contain "a" and one that does not. When looking for files containing "a", we ought to find the two, of course, and not the third one. Code:
cd /tmp Then find and xargs combination Code:
find -type f |xargs grep -l "a" Code:
./a Code:
find -type f |xargs grep -l "a" > out.txt Code:
cat out.txt Code:
./a Code:
find -type f -exec grep -l "a" '{}' \; Code:
./a Cleaning up the temporary files: Code:
rm a b ab |
Code:
grep -Rl "desired text" * |
Well, they don't call us 'Newbies' for no reason! I absolutely have no clue why this did not work for me when I posted the question, but it works now. Thank you all for the answers and for the elaborations which went beyond the question.
|
All times are GMT -5. The time now is 12:55 PM. |