Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Sed and Awk (http://www.programmingforums.org/forum22.html)
-   -   Need sed to uncomment fstab file lines. (http://www.programmingforums.org/showthread.php?t=13770)

Thaidog Aug 15th, 2007 1:13 PM

Need sed to uncomment fstab file lines.
 
Can somebody please give me an example of the sed code that could uncomment a drive mount line in fstab?

Infinite Recursion Aug 15th, 2007 2:29 PM

Is it a particular line you are interested in? Are there other commented mounts that you want to exclude? What does your fstab look like?

To remove all # in the file you could do this:

cat fileA | sed 's/#//g' > fileB; mv fileB fileA

If you want a more specific line uncommented, need more info.

Thaidog Aug 15th, 2007 6:05 PM

Quote:

Originally Posted by Infinite Recursion (Post 132243)
Is it a particular line you are interested in? Are there other commented mounts that you want to exclude? What does your fstab look like?

To remove all # in the file you could do this:

cat fileA | sed 's/#//g' > fileB; mv fileB fileA

If you want a more specific line uncommented, need more info.


There are two lines that need to be uncommented and a few others that need to stay commented.

The two that need uncommenting look like this:

#/dev/sde1 /vmware/tol ext3 nosuid 0 0
#/dev/sdf1 /vmware/sas ext3 nosuid 0 0

Infinite Recursion Aug 16th, 2007 11:47 AM

check out regular expressions and/or http://www.student.northpark.edu/pem...d/sed1line.txt

peace_of_mind Aug 16th, 2007 12:05 PM

Nice link. Thanks, IR.

Thaidog Aug 16th, 2007 4:15 PM

OK. How does this look?

sed 's/\(#\)\(/dev/sde1.*\)/\2/' /etc/fstab

sed 's/\(#\)\(/dev/sdf1.*\)/\2/' /etc/fstab

Infinite Recursion Aug 16th, 2007 4:47 PM

My shell responds with:
sed: command garbled: s/\(#\)\(/dev/sde1.*\)/\2/

You need to escape the / character... like this:

sed 's/\(#\)\(\/dev\/sde1.*\)/\2/' /etc/fstab
sed 's/\(#\)\(\/dev\/sdf1.*\)/\2/' /etc/fstab


The only difference is the sde vs sdf... regular expressions would allow you to process them with just one line. But if its a one time execution, save yourself the trouble.

You're welcome PoM... :) There is another one for Awk floating around somewhere.

Thaidog Aug 16th, 2007 5:15 PM

Quote:

Originally Posted by Infinite Recursion (Post 132302)
My shell responds with:
sed: command garbled: s/\(#\)\(/dev/sde1.*\)/\2/

You need to escape the / character... like this:

sed 's/\(#\)\(\/dev\/sde1.*\)/\2/' /etc/fstab
sed 's/\(#\)\(\/dev\/sdf1.*\)/\2/' /etc/fstab


The only difference is the sde vs sdf... regular expressions would allow you to process them with just one line. But if its a one time execution, save yourself the trouble.

You're welcome PoM... :) There is another one for Awk floating around somewhere.

It's really just a one time execution. Thanks for the help! One last thing.... would the -i switch be a good idea here? For instance:

sed -i 's/\(#\)\(\/dev\/sde1.*\)/\2/' /etc/fstab

Infinite Recursion Aug 17th, 2007 4:16 PM

It works without the -i. I would leave it as is.


All times are GMT -5. The time now is 3:11 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC