I want to add ip excluded-address which can be one or many. I dont know how to handle awk if there are many arguments it it..
suppose if i give 3 arguments eg 1.1.1.1,2.2.2.2 and 3.3.3.3
I tried above method but gave awk bailing error. So, I made a small script here which will solve your purpose but without awk
#!/bin/ksh
for i in `cat /tmp/file`
do
if [ "$i" == "excluded-address" ]
then
echo "excluded-address $1 $2 $3" >> /tmp/file
break
fi
done
You just need to supply ip address separated by comma as arguments to this script. Right now I have made this to add 3 IP address so if you want lesser or more then you can increase/decrease variables supplied with echo.
Use nawk instead on Solaris or SunOS to avoid bailing error.
Also you can use "$@" variable instead, which expands to all command-line parameters separated by spaces.
I also noticed other flaws in your script that the if condition will never match that line because it starts with a hash sign # , also that break statement is unnecessary.
The requester want to modify one particular line by appending IP address to it. Even if your script works it will not modify that particular line but append a new line to the end of file. I don't think that is what the requester want!