Results 1 to 7 of 7
How to write a command so that it will find the match to get related search word?
Code:
grep abc -f *.*
How can I search inside the directory of ...
- 11-28-2008 #1Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
Linux command using grep
How to write a command so that it will find the match to get related search word?
How can I search inside the directory of the subdirectory?Code:grep abc -f *.*
What argument that should I add?
-Henry
- 11-28-2008 #2
See "man grep" for the -R switch
Men occasionally stumble over the truth,
but most of them pick themselves up
and hurry off as if nothing had happened.
Winston Churchill
... then the Unix-Gods created "man" ...
- 11-30-2008 #3Just Joined!
- Join Date
- Feb 2008
- Posts
- 5
Thank guys...
I put all the pattern into a text files...
Code:grep -f ./test.txt -r -l *.*
which:
-f, --file=FILE obtain PATTERN from FILE
-r, --recursive equivalent to --directories=recurse.
-l, --files-with-matches only print FILE names containing matches
After I execute the command I will found all the file and it will print out the files which matches with the pattern.
Can I enhance this command so that it will take out all the files that contain matched pattern then copy and put it into a temporary place let say into a /home/fsloke/RESULT folder.
Thank you
-fsloke
- 12-03-2008 #4
You could pipe the output to the move command.
You should also look at xargs.
Men occasionally stumble over the truth,
but most of them pick themselves up
and hurry off as if nothing had happened.
Winston Churchill
... then the Unix-Gods created "man" ...
- 12-04-2008 #5Just Joined!
- Join Date
- Nov 2008
- Posts
- 4
A couple comments 1st.
a) In general, "grep -r *.*" may miss a number of files: It won't recurse into directories that don't have a '.' in their name. Even plain '*' would miss the hidden files/dirs. (only under DOS '*.*' means also '*'
I would step up to the parent directory and use "grep -r dirName" (plus you other options)
b) If your subdirs contain several files of the same name, and you are trying to copy them into one flat directory, you are attempting to overwrite the previous by the next. Even if you are using cp -R since the source for each operation is a single path/file.
Here is one way of copying selected (by grep) subtrees; it's a double tar from stdout to stdin (argument ' - ').
You run it from above your project tree.
tar -cf - $(grep -rl searchTerm aDir) | (cd /somePath ; tar -xf -)
tar -cf - $(grep -rl searchTerm aDir) | (cd /somePath ; tar -xvf -) # to see it all
I didn't add your "-f ./test.txt" to the example. Good luck.
P.S. What's 'tag' or trick to publish text in code box style?
- 12-04-2008 #6Linux User
- Join Date
- Jun 2007
- Posts
- 318
Start with a line that's left square bracket '[' followed by 'code' followed by right square bracket ']'.
End with a line that's left square bracket '[' followed by '/code' followed by right square bracket ']'.
You can use the 'Preview Post' button to see if it works before submitting the post.
- 12-05-2008 #7Just Joined!
- Join Date
- Nov 2008
- Posts
- 4
Thanks! (in hind side it's obvious...)
So let's see how well nesting is handled -- something like square Russian dolls?
'['code']'BIG BOX'['code']'small box '['tiny']' '[/code]' '['/code']' '['/code']'
I guess if I continue playing with dolls the admin will kick me out eventually,Code:BIG BOX
Code:small box
Code:tiny]
like "More than three dolls and you are out !"
After some searching I figured it's just "square HTML" with xml consistancy (phpBB?)
Thanks again. DONE.


Reply With Quote
