Pipe command question
Hi all folks,
Kindly advise why I am not allowed to execute 'pipe' command continuously. e.g. $ ls -al /dev | grep hda | grep cdrom no printout I must perform $ ls -al /dev | grep hda and then $ ls -al /dev | grep cdrom printout comes out TIA B.R. satimis |
Hi!
In your first example, you are sending the output from grep (the lines that contain 'hda') as input to next grep. So the next grep tries to find all the lines that contain 'cdrom' out of the lines that contain 'hda'. Since there are no such lines, you get no output. Elementary, my dear Watson. :) Regards Martin |
Sure you can run more "pipes" in a row. Just remember that the pipe command connects the standards out to the next standard in. ie The output of
Code:
ls -al /dev | grep hda Code:
grep cdrom use egrep and regular expressions instead. Code:
ls -al /dev/ | egrep hda\|cdrom the " a | b " thing is a regular expression that means " a or b". But since "|" is the pipe command you have to throw in the "\" to tell your shell that it is the "|" character and not the pipe command. Hope it helped. |
If you want to grep for multiples, use egrep:
ls -al /dev | egrep 'hda|cdrom' HTH EDIT: Ignore this. I really should read the earlier posts more thoroughly. DOH! |
Quote:
Thanks for your advice. That is the command I am looking for. Previously I made a mistake. I thought it will printout what is grep one by one. B.R. satimis |
Quote:
Thanks for your advice. You suggest me an additional syntax. B.R. satimis |
llamakc syntax is actually much better than mine. You can easily express more complex expressions.
Use that one. |
Quote:
B.R. satimis |
still, there are some situations you don't have choise. Remember both, they come in handy...
|
All times are GMT -5. The time now is 01:14 PM. |