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 > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 11-20-2007
grial's Avatar
grial grial is offline Forum Advisor  
El UNIX es como un toro
  
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
Quote:
Originally Posted by happyv View Post
Hello,

I have the following script to restore file and grep information. However, once it restore file, it showing a lot useless information and different to check which file have the statement "John price $200". Can I not show any information while running script. It only show..when found the string?
echo Please input list file name:
read listn
for file in `cat $listn.txt`
do
restore_file $file
cat $file |grep "John price $200"
done

expect output:
filename: XXXXXX
found string: John price $200
Try this:
Code:
echo Please input list file name:
read listn

for file in `cat $listn.txt`
do
   restore_file $file > /dev/null 2>&1
   grep "John price $200" $file > /dev/null 2>&1
   (( ! $? )) && printf "filename: $file \nfound string: \"John price $200\"\n"
done
(not tested)

Regards.