Command to Search a FILE for a STRING in multiple DIRECTORIES


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command to Search a FILE for a STRING in multiple DIRECTORIES
# 1  
Old 03-25-2015
Power Command to Search a FILE for a STRING in multiple DIRECTORIES

Hi,

Can someone please help me with a Command to Search a FILE for a STRING in multiple DIRECTORIES.

I am searching for the VIP in HTTPD.CONF in multiple httpd instances.

I am using

find ./ -name "httpd.conf" | xargs grep 10.22.0.141 cut -d: -f3- | cut -d ' ' -f4 | sort | uniq -c

but its not working

Code:
charl@rom11-TEST $ ls -latr
total 124
-rwxr-xr-x  1 root root   24 Apr  8  2014 version.signature
drwxr-xr-x  2 root root 4096 Jul 29  2014 lafiles
drwxr-xr-x  2 root root 4096 Jul 29  2014 uninstall
drwxr-xr-x  4 root root 4096 Jul 29  2014 gsk8_2015-02-24_122927.18703
drwxr-xr-x  3 root root 4096 Jul 29  2014 logs
drwxr-xr-x  2 root root 4096 Jul 29  2014 cgi-bin
drwxr-xr-x  9 root root 4096 Jul 29  2014 ..
drwxr-x---  4 root root 4096 Feb 24 12:29 gsk8_2015-02-24_124338.49359
drwxr-xr-x  2 root root 4096 Feb 24 12:48 util
drwxr-xr-x  2 root root 4096 Feb 24 12:48 example_module
drwxr-xr-x  4 root root 4096 Feb 24 12:48 modules
drwxr-xr-x  4 root root 4096 Feb 24 12:48 man
drwxr-xr-x  2 root root 4096 Feb 24 12:48 readme
drwxr-xr-x  2 root root 4096 Feb 24 12:48 include
drwxr-xr-x  3 root root 4096 Feb 24 12:48 error
drwxr-xr-x  4 root root 4096 Feb 24 12:48 gsk8
drwxr-xr-x  3 root root 4096 Feb 24 12:48 icons
drwxr-xr-x  2 root root 4096 Feb 24 12:48 codeset
drwxr-xr-x  4 root root 4096 Feb 24 12:48 java
drwxr-xr-x  9 root root 4096 Feb 24 12:48 properties
drwxr-xr-x  2 root root 4096 Feb 24 12:48 build
drwxr-xr-x  3 root root 4096 Feb 24 12:48 htdocs
drwxr-xr-x  3 root root 4096 Feb 24 12:48 bin
drwxr-xr-x  2 root root 4096 Feb 24 12:49 lib
drwxr-xr-x  2 root root 4096 Feb 24 13:16 conf
drwxr-xr-x 30 root root 4096 Mar  9 13:41 .
drwxrwxr-x  7 root root 4096 Mar  9 13:41 bofac-Wrapper
drwxr-xr-x  7 root root 4096 Jul 29  2014 bofac-admin
drwxrwxr-x  7 root root 4096 Jul 29  2014 bofac-chas-test
drwxrwxr-x  7 root root 4096 Jul 29  2014 bofac-chasdps-test
drwxrwxr-x  7 root root 4096 Oct 10 14:09 bofac-vpn-chas-test

basically the httpd instances are highlighted in red but I would ideally run the command against the entire directory.

Thanks

Last edited by Corona688; 03-25-2015 at 12:33 PM..
# 2  
Old 03-25-2015
A dot "." is a metacharacter in grep. -- matches any character

Use either grep -F [pattern], fgrep [pattern] or escape every . character in your pattern and use regular grep:
grep 10\.22\.0\.141
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

How can I use find command to search string/pattern in a file recursively?

Hi, How can I use find command to search string/pattern in a file recursively? What I tried: find . -type f -exec cat {} | grep "make" \; Output: grep: find: ;: No such file or directory missing argument to `-exec' And this: find . -type f -exec cat {} \; -exec grep "make" {} \;... (12 Replies)
Discussion started by: cola
12 Replies

3. Shell Programming and Scripting

To search multiple string in file

hi , i am having a file where i need to take ignore the data from file1.txt and redirect to another file for eg: file1.txt AUS USA file2.txt AUS,123 NZ,11 USA,12 i am using the below code (4 Replies)
Discussion started by: rohit_shinez
4 Replies

4. Shell Programming and Scripting

Search several string and convert into a single line for each search string using awk command AIX?.

I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios. Cat test Nov 10, 2012 5:17:53 AM INFO: Request Type Line 1.... (5 Replies)
Discussion started by: laknar
5 Replies

5. UNIX for Advanced & Expert Users

word search in multiple directories

need a Command in UNIX which can find out a word from files in multiple directories e.g. /home contains multiple directories /home/d1 /home/d2 . . . . /home/dn under d1,d2...dn contains multiple files. I need to search a specific word in a files under these multiple... (1 Reply)
Discussion started by: jagkoth
1 Replies

6. UNIX for Dummies Questions & Answers

Multiple search in multiple directories

Hi, I am facing the below problem I have a list of number to be searched(around 1000) files resideing in multiple directories as i dont know where it resides in. for example search string is like (abc)123456 please help. very urgent Thanks a lot Uma (3 Replies)
Discussion started by: umapearl
3 Replies

7. Shell Programming and Scripting

Search multiple strings on a file and copy the string next to it

I tried awk for this, but failed <or my code is not correct? I dont know>. Can anyone help me on this? ---------- Post updated at 08:34 PM ---------- Previous update was at 08:29 PM ---------- my working file looks like this: <empty> <empty> <empty> NAME :ABC AGE :15 GENDER... (6 Replies)
Discussion started by: kingpeejay
6 Replies

8. UNIX for Dummies Questions & Answers

problem with grep on search string in a txt file over multiple files

I have a couple of things I got stuck on 1) I have a text file containing 25k search string that I need to search against compressed file. I have used this command but somehow it doesn't seems to use all the search terms. I have put one search string per line in the txt file (I clean up... (2 Replies)
Discussion started by: m00
2 Replies

9. UNIX for Dummies Questions & Answers

Search for files in multiple directories

I want to search for a file pattern in more than one directory. How I need to do that? Here is the scenario: I am having a directory structure like the following: /log ...../20051001 ..........ftp_server_20051001.log ..........ftp_down_server.log ..........ftp_up_server.log... (7 Replies)
Discussion started by: ravikirankethe
7 Replies

10. UNIX for Dummies Questions & Answers

string search in folders with particular multiple file extension

Hi, I am newbie in UNIX so please excuse for my questions. Is there a a way to search for string in files within folder and sub folder in particluar file extensions. Ex. search for ABC in folder 'A'(including it's sub folders) in html, xml files. Thanks, Ani (2 Replies)
Discussion started by: anikanch
2 Replies
Login or Register to Ask a Question