how to put a # in a file

Hello,

Sir's,

I would like to ask for help. This is my problem, i am working for a mbs for aix,hp-ux and solaris. And i am making a script that will automatically implement the said mbs.

For example it will automatically change the permmisions of /usr/bin, /etc/passwd and so on. . . .

Now the problem is, cat /etc/inetd

i want that if it will find the word pop3,smtpd and named. it will automatically assign # in the said line.

sample:
cat /etc/inetd
pop3
named
ftpd
nfs
smtpd

output:

#pop3
#named
ftpd
nfs
#smtpd

Try this command

sed -e 's/pop3/#pop3/g' -e 's/named/#named/g' -e 's/smtpd/#smtpd/g' /etc/inetd

P.S: The above command will replace all pop3 content with "#pop3" similarly for other pattern as well.

awesome dude :slight_smile:

but wait a sec,
i jsut want that i will only mark in the 1st column,pls see below :

#pop3 stream tcp nowait root /usr/sbin/pop3d pop3

not like this:

#pop3 stream tcp nowait root /usr/sbin/pop3d #pop3

thanks a lot

try this one .. Not tested

gawk '{
if($1 ~ "pop3" || $1 ~ "smtpd" || $1 ~ "named"){print "#" $0}        
    else { print $0 }
}' my_file

it works thanks sir

Hi,

Hope this one works for you.

sed 's/\(named\)/#&/;s/\(nfs\)/#&/' filename

sed -e 's/pop3/#pop3/g' -e 's/named/#named/g' -e 's/smtpd/#smtpd/g' /etc/inetd

To replace the first occurace only you can do this

sed -e 's/pop3/#pop3/1' -e 's/named/#named/1' -e 's/smtpd/#smtpd/1' /etc/inetd

If you want insert '#' in the line start with smptd,named,pop3 then u can use this
sed -e 's/^pop3/#pop3/1' -e 's/^named/#named/1' -e 's/^smtpd/#smtpd/1' /etc/inetd