I am trying to edit the values in a file. For example i am trying to edit the value of "ABC" in a file by executing shell script.
Please Note that ABC value can be there mulitple times or it may not be there in the file
Conditions for it is
If ABC is less than 123 then it should change the ABC value to 123
If ABC is greater than 123 then it should leave the ABC value to existing value only as it is greater than 123
If ABC is not there is file then it should add ABC=123 in file.
Code i am trying is not working. PFB
if [ $ABC -lt 123 ]
then
sed -i "s|\("ABC" *= *\).*|\1123|" file.con
fi
if [ $ABC -gt 123 ]
then
"ABC=$ABC" >> file.con
else
echo "kernel.shmall=" >> /mqseries1/sysctl.conf
sed -i "s|\("kernel.shmall" *= *\).*|\1123|" file.con
fi
You didn't show us how the shell variable ABC was set in your script and there was no mention of updating kernel.shmall so I don't know what this code from your script is trying to do:
echo "kernel.shmall=" >> /mqseries1/sysctl.conf
sed -i "s|\("kernel.shmall" *= *\).*|\1123|" file.con
Unlike your script, this will leave a backup of your input file using the input filename with a leading underscore as the backup file. Although tested with a Korn shell, this will work with any shell that recognizes POSIX shell variable expansions.
By default, this script works on a file named file.con (as in your example), but you can invoke this script with one operand that names any file you want it to process.
Yes, it seems it is working. I am checking in different conditions and i will update you
---------- Post updated at 04:41 AM ---------- Previous update was at 04:36 AM ----------
Yes it is working, if i want to inclued XYZ with 456 condition where should i add condition. Actually i am looking for multiple values to check like ABC=123,XYZ=456, VFR=789.