This is my script. When I print $line, it is showing the entire line. But the grep statememt is taking it word by word. Also,the variables FOUNIT and FOUNDENT are not being set correctly.can somebody help me out?
#!/bin/ksh
cd /files/gsm
logfile=/users/gsm.txt
found=0
for i in `ls`
do
while read line
do
if [[ $found -eq 1 ]] ; then
found=0
FOUNDENT=`grep "GSM" ${line}`
if [ -z ${FOUNDENT} ]; then
echo $i |tee -a $logile
break
fi
fi
FOUNDIT=`grep "Product Value" ${line}`
if [ ! -z ${FOUNDIT} ]; then
found=0
else
found=1
fi
done< $i
done
for f in *; do tr -d '\n' < $f| grep -l '<item name="Product Value"><value>GSM</value></item>' && echo $f; done
It takes any file in the folder and removes the newlines for every file being processed. Then it greps for the string you are looking for which would be else on 3 different lines. If grep is successful, it prints the name $f of the file. At this point you could place your copy command.
The for loop will only work if no file has a blank/spaces in it. Else a while/read loop should be used for example.
I tried to execute the script you have given. But it did not echo any file where there are so many files which match this condition.Can you suggest any remedies here?
Tried again after making sure there are no typos. It did not return anything.
Not sure why.
Also, I need to fetch all filenames which have a value contains GSM (like GSM management, GSM networks etc) within the value column inside Product value. How do we modify ?
This also gives error with the first file.
ACCESS_POLICY_MANAGER
nawk: illegal statement
input record number 146, file ACCESS_POLICY_MANAGER
source line number 1