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!

trying to improve my pipes and redirection

Status
Not open for further replies.

CoolDudeeh

IS-IT--Management
Oct 21, 2003
21
0
0
US
Can anyone tell me how to do this little script on the command line in one command?
Its function is to find files containing certain text that is passed to it and the "ll" the files.
Say this script is called "fnd"
its usage is fnd text
---------------------------------------
grep -l $1 * > /tmp/list.txt
for filename in `cat /tmp/list.txt`
do
ll $filename
done
rm /tmp/list.txt
----------------------------------------
 
JUst create a new script called whatever_you_want and place the commands in there. Make the script executable. Now whenever you want to run the script, just type in whatever_you_want and the command line

HTH jocasio
 
Thanks for the reply jocasio ...... I have done exactly what you said already ..... that is what I was trying to describe ..... what I am trying to do is improve my piping and redirection skills ..... I am of the belief that the script I put in this post could be done in one command(with piping and i/o redirection) from the command line ..... that is what I am looking for.
 
Here is a one liner for searching root (/) and all subdirectories and to find searchstring in any file.

find / -type f -print | xargs grep -il searchstring

====================================================
As a script...
First parameter is the directory to start search.
Second parameter is the string to look for.

./scriptname / searchstring

inside script:

find $1 -type f -print | xargs grep -il $2

====================================================

Walter McElhannon
Questions...
walter_mcelhannon@m-chem.com
757-555-1212 (mobile)....[joking]

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top