|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Getting files which has a particular string
Hi,
There are about 200 files in a directory and I want to know if my username is present in 10 files only (I know what files I wanna look into). If I do a grep -i username, it gives me a list of all the files in the directory which has my username. But I want to know only about those 10 files. Is there a unix command for this? Thank you. -Yogesh. |
|
#2
|
|||
|
|||
|
grep -i DOES NOT give u ' a list of all the files'
but all matching lines in all files containing the string. grep -l will give a file list, but what's your Q ? if u 'I know what files I wanna look into' grep 4 string in this files! |
|
#3
|
|||
|
|||
|
Code:
for filespec in file1 file2 file3 file4 file5 .... file10
do
grep -l "username" $filespec
done
fil in the ... part with file names it's not valid syntax |
|
#4
|
|||
|
|||
|
If I have understood you correctly Jim, you want me to write a shell script and run it everytime I wanna check if username is present in those 10 files.
And what do you mean by "its not a valid syntax"? Thanks. -Yogesh. |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Getting files which has a particular string |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|