LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   awk/sed to modify /etc/fstab (https://www.linuxquestions.org/questions/linux-newbie-8/awk-sed-to-modify-etc-fstab-4175450797/)

kbscores 02-19-2013 09:17 AM

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

unSpawn 02-19-2013 09:19 AM

So what have you actually tried?

shivaa 02-19-2013 09:51 AM

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).

kbscores 02-19-2013 10:37 AM

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.


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