Sponsored Content
Top Forums Shell Programming and Scripting Command to Search a FILE for a STRING in multiple DIRECTORIES Post 302939418 by crosairs on Wednesday 25th of March 2015 10:33:00 AM
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..
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
TEST(1) 								FSF								   TEST(1)

NAME
test - check file types and compare values SYNOPSIS
test EXPRESSION [ EXPRESSION ] test OPTION DESCRIPTION
Exit with the status determined by EXPRESSION. --help display this help and exit --version output version information and exit EXPRESSION is true or false and sets exit status. It is one of: ( EXPRESSION ) EXPRESSION is true ! EXPRESSION EXPRESSION is false EXPRESSION1 -a EXPRESSION2 both EXPRESSION1 and EXPRESSION2 are true EXPRESSION1 -o EXPRESSION2 either EXPRESSION1 or EXPRESSION2 is true [-n] STRING the length of STRING is nonzero -z STRING the length of STRING is zero STRING1 = STRING2 the strings are equal STRING1 != STRING2 the strings are not equal INTEGER1 -eq INTEGER2 INTEGER1 is equal to INTEGER2 INTEGER1 -ge INTEGER2 INTEGER1 is greater than or equal to INTEGER2 INTEGER1 -gt INTEGER2 INTEGER1 is greater than INTEGER2 INTEGER1 -le INTEGER2 INTEGER1 is less than or equal to INTEGER2 INTEGER1 -lt INTEGER2 INTEGER1 is less than INTEGER2 INTEGER1 -ne INTEGER2 INTEGER1 is not equal to INTEGER2 FILE1 -ef FILE2 FILE1 and FILE2 have the same device and inode numbers FILE1 -nt FILE2 FILE1 is newer (modification date) than FILE2 FILE1 -ot FILE2 FILE1 is older than FILE2 -b FILE FILE exists and is block special -c FILE FILE exists and is character special -d FILE FILE exists and is a directory -e FILE FILE exists -f FILE FILE exists and is a regular file -g FILE FILE exists and is set-group-ID -h FILE FILE exists and is a symbolic link (same as -L) -G FILE FILE exists and is owned by the effective group ID -k FILE FILE exists and has its sticky bit set -L FILE FILE exists and is a symbolic link (same as -h) -O FILE FILE exists and is owned by the effective user ID -p FILE FILE exists and is a named pipe -r FILE FILE exists and is readable -s FILE FILE exists and has a size greater than zero -S FILE FILE exists and is a socket -t [FD] file descriptor FD (stdout by default) is opened on a terminal -u FILE FILE exists and its set-user-ID bit is set -w FILE FILE exists and is writable -x FILE FILE exists and is executable Beware that parentheses need to be escaped (e.g., by backslashes) for shells. INTEGER may also be -l STRING, which evaluates to the length of STRING. AUTHOR
Written by FIXME: ksb and mjb. REPORTING BUGS
Report bugs to <bug-coreutils@gnu.org>. COPYRIGHT
Copyright (C) 2002 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICU- LAR PURPOSE. SEE ALSO
The full documentation for test is maintained as a Texinfo manual. If the info and test programs are properly installed at your site, the command info test should give you access to the complete manual. GNU coreutils 4.5.3 February 2003 TEST(1)
All times are GMT -4. The time now is 03:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy