LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 02-19-2013, 09:17 AM   #1
kbscores
Member
 
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Rep: Reputation: 32
awk/sed to modify /etc/fstab


I'm in the process of learning sed/awk so I need a little help with editing the /etc/fstab.

I need it to take a specific line
Code:
/dev/group/mine /my/stuff  ext3     defaults        1 2
and change it to this:
Code:
/dev/group/mine /my/stuff  ext3     defaults,noauto 0 0
 
Old 02-19-2013, 09:19 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,335
Blog Entries: 55

Rep: Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535Reputation: 3535
So what have you actually tried?
 
Old 02-19-2013, 09:51 AM   #3
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Learning awk/sed and modify /etc/fstab both should not be mixed. Actually /etc/fstab is a critical file and should not be used for experiments. And even if you want, then better to be take it's backup first.

Code:
~$ awk 'BEGIN{FS=" "}; /\/dev\/group\/mine/ {gsub(/defaults/,"defaults,noauto", $4) && (/1/,"0",$5) && (/2/,"0",$6); print $0}' /etc/fstab
(Note: I didn't test it, but it can give you a rough idea).

Last edited by shivaa; 02-19-2013 at 09:54 AM.
 
Old 02-19-2013, 10:37 AM   #4
kbscores
Member
 
Registered: Oct 2011
Location: USA
Distribution: Red Hat
Posts: 259
Blog Entries: 9

Original Poster
Rep: Reputation: 32
Thank you and I will test it prior to using it.

I'm working in a lab so it is ok if I blow things up. I just needed a bit of guidance, because these statements can get long.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to modify xml file using sed/awk akhand jyoti Linux - Newbie 3 11-29-2011 02:47 PM
modify fstab keimasi Linux - General 4 03-17-2011 11:27 AM
modify a file that contains \\ using sed or awk j-me Linux - Newbie 7 05-14-2010 08:30 AM
Modify a text files with awk/sed/perl climber75 Programming 15 08-05-2008 03:35 PM
How to modify fstab? SLAY3R Linux - Newbie 7 09-18-2004 11:03 AM


All times are GMT -5. The time now is 06:22 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration