Comment lines in FSTAB using perl | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Comment lines in FSTAB using perl

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-13-2012
ajaincv ajaincv is offline
Registered User
 
Join Date: May 2011
Last Activity: 2 January 2013, 7:04 AM EST
Posts: 41
Thanks: 1
Thanked 0 Times in 0 Posts
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.

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

Code:
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

Last edited by Franklin52; 07-14-2012 at 05:35 AM.. Reason: Please use code tags for data and code samples, thank you
Sponsored Links
    #2  
Old 07-14-2012
bakunin bakunin is online now Forum Staff  
Bughunter Extraordinaire
 
Join Date: May 2005
Last Activity: 28 July 2014, 12:09 PM EDT
Location: In the leftmost byte of /dev/kmem
Posts: 4,123
Thanks: 43
Thanked 770 Times in 606 Posts
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:


Code:
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":


Code:
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
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How can i comment out a section between two particular lines proactiveaditya Shell Programming and Scripting 3 02-15-2012 02:29 AM
Trying to show lines in INI files until the comment character (#) hindesite UNIX for Dummies Questions & Answers 4 09-21-2010 06:47 PM
using awk to comment out lines to the end of file phamp008 Shell Programming and Scripting 5 07-05-2009 10:02 PM
comment lines vero_81 UNIX for Dummies Questions & Answers 5 06-11-2009 04:35 AM
how to comment multiple lines in unix balireddy_77 Shell Programming and Scripting 3 02-19-2007 06:16 AM



All times are GMT -4. The time now is 12:24 PM.