Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with grep

Status
Not open for further replies.

farley99

MIS
Feb 12, 2003
413
0
0
US
files=`grep -r test * -l | grep -v convert`

I got the first grep but
what does the
* -l | grep -v convert
do?
 
My [tt]grep[/tt] (Solaris 8) doesn't seem to have the [tt]-r[/tt] switch, so I have no idea what that means.

The [tt]-l[/tt] switch means to only output the names of the files that have a match. But it should go before the word [tt]test[/tt]. The word [tt]test[/tt] is what to look for. The [tt]*[/tt] is which files to look for [tt]test[/tt] in. So the first [tt]grep[/tt] should look like...
[tt]
grep -l test *
[/tt]
...and is only listing the names of the files that contain the word [tt]test[/tt].

The vertical bar is a pipe character. The output of the first [tt]grep[/tt] is sent to the second [tt]grep[/tt]. The second grep will exclude the file names that have "convert" in them.

On Solaris, the command should look like...
[tt]
files=`grep -l test * | grep -v convert`
[/tt]
This will make the variable "[tt]files[/tt]" contain a list of files that contain the word [tt]test[/tt], but don't have the word [tt]convert[/tt] in their name.

Hope this helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top