![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| 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 |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
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 |
|
||||
|
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.. |
|
||||
|
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 | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|