How to pass the result of a command to another command (like grep)
Hi,
I would like to pass the following command result to another command : Code:
$ grep -ri 30855 *.xml | cut -d ':' -f 1 0674.xml 0675.xml 0678.xml 0679.xml 0681.xml 0682.xml So I would like to grep the word name in each of those file. I tried Code:
grep -ri 30855 *.xml | cut -d ':' -f 1 | grep name What do I do wrong ? Thank you. |
I'm not sure I understood your intentions, but if you're trying to use the output of the first command as a list of files for the second grep, then you should include the list of files in the command line, not pipe it into grep.
Code:
grep name `grep -ri 30855 *.xml | cut -d ':' -f 1` |
Or this alternative:
Code:
grep -ri 30855 *.xml | cut -d ':' -f 1 | xargs grep name |
Here is a slightly different way to solve the problem:
Code:
grep -ri "30855\|name" *.xml | cut -d: -f1 | uniq -d |
Thank you all.
irey and Hko got it right, this is what I was trying to do. Trupen, I don't know why but your solution didn't work. |
All times are GMT -5. The time now is 08:12 PM. |