Computing.Net > Forums > Unix > Search a file

Search a file

Reply to Message Icon

Original Message
Name: krisend
Date: March 20, 2006 at 05:20:31 Pacific
Subject: Search a file
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



Report Offensive Message For Removal


Response Number 1
Name: arun.s
Date: March 26, 2006 at 23:19:01 Pacific
Subject: Search a file
Reply: (edit)

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.


Report Offensive Follow Up For Removal

Response Number 2
Name: lchi2000g
Date: April 3, 2006 at 15:35:28 Pacific
Subject: Search a file
Reply: (edit)

FIRST_AUG=1
SECOND_AUG=2

cd $TARGET_DIR

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

Luke Chi


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: Search a file

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software