Comment lines in FSTAB using perl

Hi All,

I need to comment specific Two Lines in fstab & want to do using & also want to ensure that is done corretly.

I am trying the below method. But its giving Search pattern not terminated.

################

b36376 67 % cat linux-fstab_testing | perl -i -wnl -e '/^('\Q zin46fil01:\/vol\/fil01vol09\/soft1\/\_TOOLS_\/dist \/_TOOLS_\/.dist15 ')/  and print "#$1" or print'
Search pattern not terminated at -e line 1.
b36376 68 %

#################

Please help on this

Regards

Ankit

Are you insisting in PERL? Because in fact this is a simple operation and to use PERL for this is probably overkill of the extreme sort. The following solution is sed and will do the job:

sed 's/^[<spc><tab>]*zin46fil01:\/vol\/fil01vol09\/soft1\/\_TOOLS_\/dist \/_TOOLS_\/.dist15/# &/' /etc/fstab > /tmp/sed.$$
mv /etc/fstab /etc/fstab.${DATE}
mv /tmp/sed.$$ /etc/fstab

I assumed the variable "$DATE" here, which is part of my environment, because i like to have date-coded backup files if i let something change via a script. If you don't have such a variable either create one before or even dump the command altogether if you don't need a backup copy.

Replace "<spc>" and "<tab>" with literal spaces/tabs. If you have more than one line to comment out just duplicate the line and change the path accordingly. The "&" in the replacement part means "everything matched by the regexp before":

sed 's/^[<spc><tab>]*\/path\/to\/mount1/# &/
     s/^[<spc><tab>]*\/path\/to\/mount2/# &/' /etc/fstab > /tmp/sed.$$
mv /etc/fstab /etc/fstab.${DATE}
mv /tmp/sed.$$ /etc/fstab

I hope this helps.

bakunin