The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > AIX
.
google unix.com



AIX AIX is IBM's industry-leading UNIX operating system that meets the demands of applications that businesses rely upon in today's marketplace.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
find and replace string in a directory files koti_rama Shell Programming and Scripting 2 05-30-2008 03:48 AM
awk command to find the count of files ina directory sish78 Shell Programming and Scripting 11 07-19-2007 08:00 AM
How to delete Directory and inside files using Find command bmkreddy SUN Solaris 3 07-10-2007 02:35 PM
Unix find command to print directory and search string princein UNIX for Dummies Questions & Answers 4 03-06-2007 08:46 AM
How to find all the log files under the root directory -- Need Info gkrishnag UNIX for Advanced & Expert Users 2 09-06-2006 03:38 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-16-2007
Subbu_Angeline Subbu_Angeline is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 1
Help Using Grep command to Find the string in the files in the root directory

I want to serch for a string in all the files in the root directory. i want the search to be limited to only the files in the directory i.e the search to be done only in the files not in the sub directory.

the approaches tried are
1)grep "pattern string"
this command was serching the pattern in all the files in the root directory as well as in the sub directories which is not required.
2)grep "pattern string" `find . -type f -print -o -type d -prune`
this was not giving any result
3) grep -| "pattern" *.txt
it says the pattern not found . but the pattern is present in files in the directory

one approach to this i have thought listing all the files in the root directory and not in the sub directory and then passing the output of this in the grep command. tell me if this is possible.

if possible it would be helpful if i am able to get the rite syntax for find command only.

Can some one please help me with this
  #2 (permalink)  
Old 01-16-2007
funksen funksen is offline Forum Advisor  
Registered User
  
 

Join Date: Nov 2006
Location: Austria/Vienna
Posts: 430
ls -l | grep -v '^d' | awk '{print $NF}' | while read i
do
grep "$i" pattern
done

not tested but should do the job

there must be faster ways but I've no time to read man pages now

Last edited by funksen; 01-17-2007 at 08:34 AM..
  #3 (permalink)  
Old 01-17-2007
TheEngineer TheEngineer is offline
Registered User
  
 

Join Date: Apr 2006
Location: Iraq
Posts: 36
also you can do as follows:

ls -l|grep -v "^d"|awk '{print $9}'|xargs grep <pattern>

this way has been tested and should do the search only on search able files and avoidng any special files if there is.
  #4 (permalink)  
Old 01-17-2007
TheEngineer TheEngineer is offline
Registered User
  
 

Join Date: Apr 2006
Location: Iraq
Posts: 36
also you can do as follows:

ls -l|grep -v ^[dbc]|awk '{print $9}'|xargs grep <pattern>

this way has been tested and should do the search only on any files in the current directory avoiding any special files that might be there.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0