![]() |
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 |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how to make your bash script run on a machine with csh and bash | npatwardhan | Shell Programming and Scripting | 3 | 11-19-2008 04:17 AM |
| Script to find, grep and email | basisvasis | Shell Programming and Scripting | 7 | 09-21-2008 07:03 PM |
| Speeding up a Shell Script (find, grep and a for loop) | Dave Stockdale | UNIX for Dummies Questions & Answers | 8 | 08-11-2008 04:36 AM |
| passing variable from bash to perl from bash script | arsidh | Shell Programming and Scripting | 10 | 06-04-2008 12:25 PM |
| command find returned bash: /usr/bin/find: Argument list too long | yacsil | Shell Programming and Scripting | 1 | 12-15-2003 06:38 PM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
||||
|
Bash script (using find and grep)
I'm trying to make a simple search script but cannot get it right. The script should search for keywords inside files. Then return the file paths in a variable. (Each file path separated with \n).
Code:
#!/bin/bash
SEARCHQUERY="searchword1 searchword2 searchword3";
for WORD in $SEARCHQUERY
do
GREPINPUT=$GREPINPUT" | grep --ignore-case --files-with-matches -e '$WORD'";
done
FINDFILES=$(find . -maxdepth 2 -name \*.c -type f $($GREPINPUT));
|
|
||||
|
I usually search inside a file with:
Code:
cd /home/users/; grep -R "keyword" * | gawk -F: '{ print $1 }' >> output.txt
Play around with that in your script, should be fun! |
|
||||
|
How about:
Code:
#!/bin/bash SEARCHQUERY="searchword1|searchword2|searchword3" FINDFILES=$(find . -maxdepth 2 -name \*.c -type f |xargs egrep -lie "$SEARCHQUERY") Code:
FINDFILES=$(find . -maxdepth 2 -name \*.c -type f -exec egrep -lie "$SEARCHQUERY" {} \; )
|
|
||||
|
An AND function, but not on the same line and not necessarily in that order? OK, I think this might work:
Code:
#!/bin/bash Q1="searchword1"; Q2="searchword2"; Q3="searchword3"; FINDFILES=$(find . -maxdepth 2 -name \*.c -type f |xargs grep -li "$Q1"|xargs grep -li "$Q2"|xargs grep -li "$Q3") Last edited by Scrutinizer; 5 Days Ago at 12:37 PM.. |
| Sponsored Links | ||
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|