Help in awk

i have a file with following entries in it

# global_start
# database 
# client default-router distance 
# excluded-address
# ping packets 
# ping timeout 

#global_end

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..:confused:
suppose if i give 3 arguments eg 1.1.1.1,2.2.2.2 and 3.3.3.3

then the file should be modified as

# global_start
# database 
# client default-router distance 
excluded-address 1.1.1.1 2.2.2.2 3.3.3.3
# excluded-address
# ping packets 
# ping timeout 

#global_end

can anybody help

echo "Enter IP excluded address: "
read ipexaddr

awk -v I="$ipexaddr" '/excluded-address/{sub("# ","",$0);$0=$0" "I;}1' filename

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.

That is a Useless Use of cat and dangerous backticks

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.

Please do test your script before posting.

Well, it works. I have tested.

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!