Computing.Net > Forums > Unix > Search a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Search a file

Reply to Message Icon

Name: krisend
Date: March 20, 2006 at 05:20:31 Pacific
OS: UNIX
CPU/Ram: 512
Comment:

Hi All,

Can anyone tell me how to search for a file.
I have to pass two parameters. The content of the file should contain the value of two parameters.
If the file contains one parameter it should not be picked up.

Thanks
Kris




Sponsored Link
Ads by Google

Response Number 1
Name: arun.s
Date: March 26, 2006 at 23:19:01 Pacific
Reply:

hi Kris,

Check this out.

____________________________
#!/bin/ksh

echo "Enter two parameters "
read arg1
read arg2

echo "Enter search location "
read loc

cd $loc
ls | while read file
do
var1=`grep "$arg1" $file | wc -l` var2=`grep "$arg2" $file | wc -l`
if [ "$var1" -ne 0 ] || [ "$var2" -ne 0 ]; then
echo $file
fi
done


thanks
Arun S


this unix location and u have placed windows request. please specify on which platform u want solution.


0

Response Number 2
Name: lchi2000g
Date: April 3, 2006 at 15:35:28 Pacific
Reply:

FIRST_AUG=1
SECOND_AUG=2

cd $TARGET_DIR

grep -l $SECOND_AUG `grep -l $FIRST_AUG *`

Luke Chi


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Search a file

formatting a file www.computing.net/answers/unix/formatting-a-file/2735.html

Help: how do i search a file? www.computing.net/answers/unix/help-how-do-i-search-a-file/4660.html

search for word/s in a file www.computing.net/answers/unix/search-for-words-in-a-file/8147.html