Sponsored Content
Full Discussion: Recursive grep
Top Forums UNIX for Dummies Questions & Answers Recursive grep Post 302195815 by era on Friday 16th of May 2008 02:41:55 AM
Old 05-16-2008
The relative path to file2 seems wrong; the output redirection is relative to the current directory, not the directory of the file you are grepping.

The relative pat you are grepping seems wrong too; /../ is equivalent to / is equivalent to /../../../../../

The backticks in the for loop are what are splitting up stuff on whitespace. Use a construct which is less sensitive to spacing issues, or use proper quoting.

Code:
for h in "`cat file1`"; do grep -rl "$h" pathtodir >>file2; done

or

Code:
while read h; do grep -rl "$h" pathtodir >>file2; done<file1

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

grep recursive directories

I am trying to locate a file or files with specific data in them. Problem is the file(s) could reside in any one of many directories. My question is. Is there a way of recursively greping directories for the file(s) with the data I am looking for. I have tried - 1. $HOME> grep 47518 | ls... (8 Replies)
Discussion started by: jagannatha
8 Replies

2. UNIX for Dummies Questions & Answers

recursive GREP ?

Hi! Suppose I have a directory (no symbolic links) called /WORK that contains 3 subdirectories: /A /B /C My problem is this: I want to look for a file that contains an order number. So far, I obtain what I want by doing this /home/acb% cd /WORK/A /home/acb/WORK/A% grep '093023553' *.*... (3 Replies)
Discussion started by: alan
3 Replies

3. UNIX for Dummies Questions & Answers

recursive grep output

I'm using this command to get a recursive grep find . -name *.i -exec grep 'blah blah' {} \; -exec ls {} \; now I would like to obtain just the list of the files and not also the line of the file. How should I change the syntax? thank you, (5 Replies)
Discussion started by: f_o_555
5 Replies

4. Shell Programming and Scripting

Preventing an endless loop with recursive grep

When finding a string in files within a directory, one can use this: grep -r "searchstring" dir/subdir/ > listofoccurrences.txt For brevity sake one can enter the intended directory and use this: grep -r "searchstring" . > listofoccurrences.txt which as I found out leads to an endless loop,... (2 Replies)
Discussion started by: figaro
2 Replies

5. UNIX for Advanced & Expert Users

recursive grep

Hi, on AIX 6.1 , in man document for grep : -r Searches directories recursively. By default, links to directories are followed. But when I use : oracle@XXX:/appli/XXX_SCRIPTS#grep -r subject *.sh It returns nothing. However I have at least one row in a file : ... (3 Replies)
Discussion started by: big123456
3 Replies

6. Shell Programming and Scripting

Tricky recursive removal (find with grep)

Tricky one: I want to do several things all at once to blow away a directory (rm -rf <dir>) 1) I want to find all files recursively that have a specific file extension (.ver) for example. 2) Then in that file, I want to grep for an expression ( "sp2" ) for example. 3) Then I want to... (1 Reply)
Discussion started by: jvsrvcs
1 Replies

7. Shell Programming and Scripting

Recursive Grep with replace

I have seen some useful infomation about recursive grep in one of the thread. Can it is possible to combine resursive grep and replace togather? Means I need to replace old server names in all the files with new server names as we are upgrading our applications. There are lots of files in... (2 Replies)
Discussion started by: yale_work
2 Replies

8. Shell Programming and Scripting

Recursive find / grep within a file / count of a string

Hi All, This is the first time I have posted to this forum so please bear with me. Thanks also advance for any help or guidance. For a project I need to do the following. 1. There are multiple files in multiple locations so I need to find them and the location. So I had planned to use... (9 Replies)
Discussion started by: Charlie6742
9 Replies

9. UNIX for Advanced & Expert Users

Recursive grep with only certain types of files

Can I please have some ideas on how to do a recursive grep with certain types of files? The file types I want to use are *.c and *.java. I know this normally works with all files. grep -riI 'scanner' /home/bob/ 2>/dev/null Just not sure how to get it to work *.c and *.java files. (5 Replies)
Discussion started by: cokedude
5 Replies
mv(1)							      General Commands Manual							     mv(1)

Name
       mv - move or rename files

Syntax
       mv [-i] [-f] [-] file1 file2

       mv [-i] [-f] [-] file... directory

Description
       The command moves (changes the name of) file1 to file2.

       If  file2  already  exists,  it is removed before file1 is moved.  If file2 has a mode which forbids writing, prints the mode and reads the
       standard input to obtain a line.  If the line begins with y, the move takes place.  If it does not, exits.  For further information, see

       In the second form, one or more files (plain files or directories) are moved to the directory with their original file-names.

       The command refuses to move a file onto itself.

Options
       -		   Interprets all following arguments as file names to allow file names starting with a minus.

       -f		   Force. This option overrides any mode restrictions or the -i switch.

       -i		   Interactive mode.  If a move is to supersede an existing file, the system prompts youw with the name of the	file  fol-
			   lowed  by  a question mark.	If you type a string that begins with y, the move occurs.  If you type any other response,
			   the move does not occur.

Restrictions
       If file1 and file2 lie on different file systems, must copy the file and delete the original.  In this case the owner name becomes that	of
       the copying process and any linking relationship with other files is lost.

See Also
       cp(1), ln(1)

																	     mv(1)
All times are GMT -4. The time now is 04:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy