Hello,
I have a .htaccess file as follows... No I want to comment the last line ( in this case.. it may not be a last line for other cases).. please advise how to add a # (comment infront of "Options All -Indexes" not assuming this line to be the last line using sed.
root@server1 [/home/name/public_html]# cat .htaccess
# -FrontPage-
IndexIgnore .htaccess */.??* ~ # */HEADER */README */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
Options All -Indexes
root@server1 [/home/name/public_html]#
Result should be like
------------------------
root@server1 [/home/name/public_html]# cat .htaccess
# -FrontPage-
IndexIgnore .htaccess */.??* ~ # */HEADER */README */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
#Options All -Indexes
root@server1 [/home/name/public_html]#
Please advise.
Thanks.
sed 's/Options All -Indexes/#Options All -Indexes/' filename
assuming single occurrence of pattern
else use /g
Thanks... works beautifully.
How about say.. I have some 50 files in a folder... which are actually valiases files.. where the catch all or default address is set as ....
*: username for a domain... xyz.com
*: username1 for a domain... abc.com
I.e.
if you do ..
cat /etc/valiases/xyz.com
*: username
cat /etc/valiases/abc.com
*: username1
cat /etc/valiases/def.com
*: username2
Now.. i want to replace all instances of ..
*: username2 or *: username or *: username1 to
*: :fail: No Such Address Here
So after conversion..
cat /etc/valiases/def.com
*: :fail: No Such Address Here
same for other domains..
Can you please advise.
Thanks.
perl -i -ne ' print "*: :fail: No Such Address Here\n" if( /^\*:/ ) ' /etc/valiases/*.com
sed 's/\*: username.*/\*: :fail: No Such Address Here/' file
Hello,
Its working.. but it prints the output.. how can I make a script so that it changes the line automatically.
root@dallas [/opt/abc]# sed 's/\: username.*/\ : :fail: No Such Address Here/g' *
*: :fail: No Such Address Here
*: :fail: No Such Address Here
*: :fail: No Such Address Here
root@dallas [/opt/abc]# cat abc.com
*: username1
root@dallas [/opt/abc]# ls
./ ../ abc.com def.com xyz.com
root@dallas [/opt/abc]#
This doesnot seem to be working.
-------------------------------------
root@dallas [/opt/abc]# perl -i -ne ' print ": :fail: No Such Address Here\n" if( /^\ ) ' /etc/valiases/*.com
root@dallas [/opt/abc]# cat abc.com
*: username1
This command has changed files in /etc/valiases directory. In which directory are you checking the files?
Ok..
Thanks a lot to both of you.
Its working now
root@dallas [/opt/abc]# perl -i -ne ' print ": :fail: No Such Address Here\n" if( /^\ ) ' /opt/abc/*.com
root@dallas [/opt/abc]# cat *
*: :fail: No Such Address Here
*: :fail: No Such Address Here
*: :fail: No Such Address Here
In case of files with any suffix,
root@dallas [/opt/abc]# perl -i -ne ' print ": :fail: No Such Address Here\n" if( /^\ ) ' /opt/abc/*
root@dallas [/opt/abc]# cat *
*: :fail: No Such Address Here
*: :fail: No Such Address Here
*: :fail: No Such Address Here
root@dallas [/opt/abc]#
However I would love to use sed.
fed.linuxgossip:
Ok..
Thanks a lot to both of you.
Its working now
root@dallas [/opt/abc]# perl -i -ne ' print ": :fail: No Such Address Here\n" if( /^\ ) ' /opt/abc/*.com
root@dallas [/opt/abc]# cat *
*: :fail: No Such Address Here
*: :fail: No Such Address Here
*: :fail: No Such Address Here
In case of files with any suffix,
root@dallas [/opt/abc]# perl -i -ne ' print ": :fail: No Such Address Here\n" if( /^\ ) ' /opt/abc/*
root@dallas [/opt/abc]# cat *
*: :fail: No Such Address Here
*: :fail: No Such Address Here
*: :fail: No Such Address Here
root@dallas [/opt/abc]#
However I would love to use sed.
for file in /opt/abc/*
do
sed 's/\*: username.*/\*: :fail: No Such Address Here/g' "$file" > tmp
mv tmp "$file"
done
root@dallas [/opt/abc]# cat /root/x
for file in /opt/abc/*
do
sed 's/\: username.*/\ : :fail: No Such Address Here/g' "$file" > tmp
mv tmp "$file"
done
root@dallas [/opt/abc]#
root@dallas [/opt/abc]# cat abc.com
*: ddde
root@dallas [/opt/abc]#
root@dallas [/opt/abc]# cat def.com
*: asdsadas
root@dallas [/opt/abc]#
root@dallas [/opt/abc]# cat xyz.com
*: srfasdrdsaf
root@dallas [/opt/abc]#
root@dallas [/opt/abc]# /root/x
root@dallas [/opt/abc]# cat *
*: ddde
*: asdsadas
*: srfasdrdsaf
root@dallas [/opt/abc]#
suggest its now working.
command I posted will give the modified version of the source file.
to effect the changes use GNU sed
or
do it has,
sed command > temp
mv temp orig
Interesting results
----------------------------
root@dallas [/opt/abc]# cat *
*: ddde
: asdsadas
: srfasdrdsaf
root@dallas [/opt/abc]# sed 's/\ : */\ : :fail: No Such Address Here/' abc.com
*: :fail: No Such Address Hereddde
root@dallas [/opt/abc]#
root@dallas [/opt/abc]# cat abc.com
*: ddde
root@dallas [/opt/abc]# sed 's/\: */\ : :fail: No Such Address Here/' abc.com > temp ; mv -f temp abc.com
root@dallas [/opt/abc]# cat abc.com
*: :fail: No Such Address Hereddde
root@dallas [/opt/abc]#
so it adds ddde at the end after "No Such Address Here"
Dangerous.........
It wipes out other forwarders..
say..
s@y.com : a@b.com
*: username
After running the perl command...
it leaves only.
*: :fail: No Such User Here.