Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 15th, 2007, 12:13 PM   #1
Thaidog
Newbie
 
Join Date: Sep 2004
Posts: 8
Rep Power: 0 Thaidog is on a distinguished road
Question 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?
Thaidog is offline   Reply With Quote
Old Aug 15th, 2007, 1:29 PM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,436
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 15th, 2007, 5:05 PM   #3
Thaidog
Newbie
 
Join Date: Sep 2004
Posts: 8
Rep Power: 0 Thaidog is on a distinguished road
Exclamation

Quote:
Originally Posted by Infinite Recursion View Post
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
Thaidog is offline   Reply With Quote
Old Aug 16th, 2007, 10:47 AM   #4
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,436
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
check out regular expressions and/or http://www.student.northpark.edu/pem...d/sed1line.txt
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 16th, 2007, 11:05 AM   #5
peace_of_mind
Professional Programmer
 
peace_of_mind's Avatar
 
Join Date: Sep 2004
Location: Hell if I know most of the time
Posts: 435
Rep Power: 4 peace_of_mind is on a distinguished road
Send a message via MSN to peace_of_mind Send a message via Yahoo to peace_of_mind
Nice link. Thanks, IR.
__________________
Amateurs built the ark
Professionals built the Titanic

peace_of_mind is offline   Reply With Quote
Old Aug 16th, 2007, 3:15 PM   #6
Thaidog
Newbie
 
Join Date: Sep 2004
Posts: 8
Rep Power: 0 Thaidog is on a distinguished road
OK. How does this look?

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

sed 's/\(#\)\(/dev/sdf1.*\)/\2/' /etc/fstab
Thaidog is offline   Reply With Quote
Old Aug 16th, 2007, 3:47 PM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,436
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
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.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Aug 16th, 2007, 4:15 PM   #8
Thaidog
Newbie
 
Join Date: Sep 2004
Posts: 8
Rep Power: 0 Thaidog is on a distinguished road
Exclamation

Quote:
Originally Posted by Infinite Recursion View Post
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
Thaidog is offline   Reply With Quote
Old Aug 17th, 2007, 3:16 PM   #9
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,436
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
It works without the -i. I would leave it as is.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
problem processing file into a char array csrocker101 C++ 1 May 8th, 2007 11:50 PM
converting string to float beginnerCCC C 22 Oct 2nd, 2006 11:59 PM
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 8:55 AM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:28 PM.

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