Results 1 to 4 of 4
I am having trouble to grep a command result against another. I am trying to take the ls -la command and then grep this against a script that was written ...
- 11-09-2006 #1Just Joined!
- Join Date
- Nov 2006
- Posts
- 1
grep off a command
I am having trouble to grep a command result against another. I am trying to take the ls -la command and then grep this against a script that was written called dates.sh. I though the syntax is:
ls -la|grep $dates.sh|less
Any help is greatly appreciated. Thanks.
- 11-09-2006 #2
Try
(Although if you're only expecting one result, it's not necessary to pipe the output to less.)Code:ls -la | grep 'dates.sh' | less
- 11-09-2006 #3Linux User
- Join Date
- Aug 2005
- Posts
- 408
ls -la|grep $dates.sh|less
If you're writing it like this, the problem is that you need spaces between your pipes.
In addition, it's not a variable, but a filename you're looking for, so you need no "$". In addition, there is nothing to pipe into the program "less" because you're just looking for the entry with list. If you want to feed the whole script into less and you know it's there, you only need to pass the name of the file to less, like so:Code:ls -la | grep dates.sh
Code:less dates.sh
- 11-09-2006 #4
Well, this is somewhat unclear.
Are you trying to find the results of the ls inside of the dates.sh file? Or are you trying to find the text 'dates.sh' inside of the ls output?
If the former, this will not work: you will actually need to use the "xargs" command. Something like this:
Code:ls -la | xargs -I{} grep -H '{}' dates.shDISTRO=Arch
Registered Linux User #388732


Reply With Quote