Execute grep command within a folder


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Execute grep command within a folder
# 1  
Old 06-10-2009
Execute grep command within a folder

Experts,

i need your help to made an enhance query using the existing one. i'm using a command "find . -exec grep -l 'search string' {} \;" to search a particular sting within the file within a folder. Basically, my idea is to fine tune my search. What i want is, instead of searching all files within a folder can it be possible that the my query searches only those fileNAME which ends with particular string?

eg. below are the files name within a folder.
ICH860_20080522-221757_377
ICH860_20080713-200443_364
ICH860_20080724-013915_491
ICH860_20080724-020524_828
ICH860_20080805-063200_377
ICH860_20081208-061849_377

i want my query "find . -exec grep -l 'search string' {} \;" to search only those filesname which ends with '_377'. If this happen, my search will give me 3 files names only.

I hope i used simple/easy language. If still, its not clear please do let me know.

Gaurav.
# 2  
Old 06-10-2009
try:
Code:
find . -name '*_377' -exec grep -l 'search string' {} \;

how about adding -type f option as well?
# 3  
Old 06-10-2009
Thanks Yogesh!! it works. My search time is drastically reduced.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to execute 10 sql files from a folder through sqlplus in shell script?

I am new to shell scripting and i want to know how to execute the *.sql files from a folder through sqlplus in shell script and files should be execute in sequentially one by one while execution if any ORA error it has to exit from sqlplus session 1) scripts from external folder 2) logs has... (1 Reply)
Discussion started by: sreekanth Reddy
1 Replies

2. Shell Programming and Scripting

Execute script in Folder with Lower & Upper case

My script test.sh requires an argument and it could be present on a list of servers under a folder with name either in upper or lower case like below: For example: i want a generic command for calling the test.sh script and pass one argument Below is what i tried but it is failing ... (10 Replies)
Discussion started by: mohtashims
10 Replies

3. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

4. Shell Programming and Scripting

Execute multiple files in multiple folders and also output on same folder

How to execute multiple files in multiple folders and also output to be generated in the same folder? Hello Team, I have a path like Sanity_test/*/* and it has around 100+ folders inside with files. I would like to run/execute those files and output of execution to be placed on same /... (1 Reply)
Discussion started by: pushpabuzz
1 Replies

5. Red Hat

Use of Execute permission for folder

Hi All, What is the use of execute permission for a folder. I know "for execute a file(script file) we have to provide execute permission to that respective file".But what is the use to give execute permission to folder.Is it equal to read permission ? Regards, Mastan (1 Reply)
Discussion started by: mastansaheb
1 Replies

6. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

7. Shell Programming and Scripting

Execute commands to specific folder from input file

Hi, I have one text file input.txt, which has folders path as follows: /home/user/automate/abc /home/user/automate/abc/xyz /home/user/automate/test /home/user/automate/test2 /home/user/automate/test2/abc/Main In those folders i have .svn folder. 1) First i want to remove .svn like rm... (5 Replies)
Discussion started by: dragon.1431
5 Replies

8. Shell Programming and Scripting

How to execute Grep in Perl.

$ grep edge test_1 |sort|uniq >result.txt $more result.txt edge-a-pas01.com 10.12.10.11 edge-b-pas02.com 10.12.10.12 edge-c-pas03.com 10.12.10.50 edge-d-pas03.com 10.12.10.10 how do we execute the above grep command using perl? Thanks in advance. (3 Replies)
Discussion started by: sureshcisco
3 Replies

9. Shell Programming and Scripting

Use grep result to execute next command

Hi I am trying to run 2 servers using a script one after the other. I start the first one: run.sh -c servername >> jboss_log.txt & Then I have to wait until I see Started message in the log file before I launch the other server. I can't use sleep because I am not sure how long it'll... (5 Replies)
Discussion started by: iririr
5 Replies

10. UNIX for Dummies Questions & Answers

Grep from different folder

Hi All, Need your assistance/advice. I have 4 folders but using same name log file. /user/access/server1 /user/access/server2 /user/access/server3 /user/access/server4 filename is access.log.20060716.gz I want to grep the transaction id in the log file but I want to do... (2 Replies)
Discussion started by: nazri76
2 Replies
Login or Register to Ask a Question