Search and replace a number

a=`grep  -i a.sh filename.sh|cut -d "|" -f4`
b=`expr $a + 1`
filename=`grep  -i a.sh filename.sh`
while read line
do
echo $line
echo  $filename
if [ $line = $filename ]
then
echo "entered if"
nawk  ' BEGIN { FS="|"; OFS="|" }
{ sub('$a', '$b', $4)
print $0}'  filename.sh
fi
echo "exit if"
done < filename.sh

filename.sh

User  |id |file|count
--------------------------
oracle|0123|a.sh|0
oracle|0124|b.sh|1
oracle|0125|c.sh|3
oracle|0126|d.sh|0
oracle|0127|e.sh|1
oracle|0128|f.sh|3

expected output

User |id |file|count
--------------------------
oracle|0123|a.sh|1
oracle|0124|b.sh|1
oracle|0125|c.sh|3
oracle|0126|d.sh|0
oracle|0127|e.sh|1
oracle|0128|f.sh|3

Every time i grep a file name in the file, the counter has to get updated by 1.

I tried this command, if the counter is same for other line, then changes for all the line which are same numbers, i require for single line update, please help me.......

regards,
giri

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Continue here:

http://www.unix.com/unix-dummies-questions-answers/134274-search-replace-number.html\#post302412578

Thank You.

The UNIX and Linux Forums.