LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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-28-2019, 02:12 AM   #1
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
Unable to edit fstab with sed to edit mount options


Hi LQ,

This is my target file & it's contents..

Code:
vim /tmp/fstab_bk
# Commented Line followed by empty line
/dev/mapper/vg_root-lv_root     /       ext4    defaults 1 2
UUID=STRING1       /boot   ext4    defaults 1 2
/dev/mapper/vg_root-lv_home     /home   ext4    defaults 1 2
/dev/mapper/vg_root-lv_opt      /opt    ext4    defaults 1 2
# Commented Line followed by empty line

/dev/mapper/vg_root-lv_tmp      /tmp    ext4    defaults,noexec         1       2
/dev/mapper/vg_root-lv_usr      /usr    ext4    defaults 1 2
/dev/mapper/vg_root-lv_var      /var    ext4    defaults 1 2
/dev/mapper/vg_root-lv_swap     swap    swap    defaults 1 2
tmpfs   /dev/shm        tmpfs   nodev,nosuid,noexec     0       0
devpts  /dev/pts        devpts  STRING2  0       0
sysfs   /sys    sysfs   defaults 1 2
proc    /proc   proc    defaults 1 2
/tmp    /var/tmp        none    bind,nodev,nosuid,noexec    0      0
/dest1  /MP1    ext4    defaults,nodev 1 2
/dest2         /MP2      ext3    defaults 1 2
# Commented Line followed by empty line

/dest3           /MP3                  ext4    defaults        1       2
I am trying to write a script that would add 'nosuid' option for all non-root filesystems. So, my output file should be something like this -

Code:
# Commented Line followed by empty line
/dev/mapper/vg_root-lv_root     /       ext4    defaults 1 2
UUID=STRING1       /boot   ext4    defaults 1 2
/dev/mapper/vg_root-lv_home     /home   ext4    defaults 1 2
/dev/mapper/vg_root-lv_opt      /opt    ext4    defaults 1 2
# Commented Line followed by empty line

/dev/mapper/vg_root-lv_tmp      /tmp    ext4    defaults,noexec         1       2
/dev/mapper/vg_root-lv_usr      /usr    ext4    defaults 1 2
/dev/mapper/vg_root-lv_var      /var    ext4    defaults 1 2
/dev/mapper/vg_root-lv_swap     swap    swap    defaults 1 2
tmpfs   /dev/shm        tmpfs   nodev,nosuid,noexec     0       0
devpts  /dev/pts        devpts  STRING2  0       0
sysfs   /sys    sysfs   defaults 1 2
proc    /proc   proc    defaults 1 2
/tmp    /var/tmp        none    bind,nodev,nosuid,noexec    0      0
/dest1  /MP1    ext4    defaults,nosuid,nodev 1 2
/dest2         /MP2      ext3    defaults,nosuid 1 2
# Commented Line followed by empty line

/dest3           /MP3                  ext4    defaults,nosuid        1       2
I understand that I first need to discard all root and runtime directories (/proc, /dev/shm and such), so I can not do a blind sed string replacement on the file itself. Right now I can replace the string on the line output-

Code:
for i in $(cat /tmp/fstab_bk | grep -Ev "^$|^#|vg_root|UUID|nosuid|proc|sysfs|devpts"| awk '{print $1, $4}');do  echo "string is $i";echo $i | sed  's/defaults/defaults,nosuid/'  ; done
string is /dest1
/dest1
string is defaults,nodev
defaults,nosuid,nodev
string is /dest2
/dest2
string is defaults
defaults,nosuid
string is /dest3
/dest3
string is defaults
defaults,nosuid
This looks hopeful and my approach this problem is to match the $1 value with the first column of the file (so, matching /destN) and check if $4 contains the string "default" and replace it with "defaults,nosuid" for those lines only. For the life of me, I can't achieve this.

Here's what I am trying, but I am guessing there are syntax errors here -
Code:
]#  for i in $(cat /tmp/fstab_bk | grep -Ev "^$|^#|vg_root|UUID|nosuid|proc|sysfs|devpts"| awk '{print $1}';
do
sed -i -e '/^$i / s/defaults/defaults,nosuid/' /tmp/fstab_bk
done
>
I am specifically looking for a one liner and since I am pretty mediocre in sed, a bit of explanation would be awesome too. Can I please get some pointers ? Also, it'd be interesting to show other approaches as well.
 
Old 02-28-2019, 03:11 AM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
This is too complex for my poor brain, but this line:
Code:
sed -i -e '/^$i / s/defaults/defaults,nosuid/' /tmp/fstab_bk
will perform the substitution in lines that start with dollar-i. Since there are no such lines, it does nothing. If you want $i to be interpreted as a shell variable, use double quotes around the sed expression.

Since you use awk anyway, why not use it for the substitution as well? I don't know if awk has an option that is equivalent to sed's -i, but this is easily worked around.

You can discard unwanted lines by checking the second column (for root) or column 3:
Code:
$2=="/" || $3=="tmpfs" || $3=="devpts" || (...etc...) { next }
Then, in the remaining lines, add nosuid to the fourth columm:
Code:
{ $4 = $4 ",nosuid"; print }
That should be it, more or less. Not a one-liner, but perhaps easier to read than your construct.

Last edited by berndbausch; 02-28-2019 at 03:12 AM.
 
Old 02-28-2019, 04:06 AM   #3
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420

Original Poster
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
Thanks for your attention @berndbausch

Code:
sed -i -e '/^$i / s/defaults/defaults,nosuid/' /tmp/fstab_bk
Quote:
will perform the substitution in lines that start with dollar-i. Since there are no such lines, it does nothing.
Sorry, could you please explain that ? Because $i is actually holding the value for first column of the fstab file.
Code:
# for i in $(cat /tmp/fstab_bk | grep -Ev "^$|^#|vg_root|UUID|nosuid|proc|sysfs|devpts"| awk '{print $1}');do  echo "string is $i"; done
string is /dest1
string is /dest2
string is /dest3
I am trying to construct the awk script with your method and will post results.
 
Old 02-28-2019, 04:19 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Sorry, could you please explain that ? Because $i is actually holding the value for first column of the fstab file.
Your problem is that shell variables are not resolved inside single quotes. When quoted like this, a dollar is a dollar. No replacement.

Use double quotes instead. In my mother tongue, Gänsefüßchen (much cuter, I think). Try this:
Code:
i=123
echo ‘$i’
echo “$i”

Last edited by berndbausch; 02-28-2019 at 04:22 AM.
 
Old 02-28-2019, 04:40 AM   #5
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420

Original Poster
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
Ah correct, overlooked that.
 
Old 02-28-2019, 11:25 AM   #6
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420

Original Poster
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
attempt with awk

@berndbausch, tried awk too. Maybe you could help in streamlining this ?

Code:
 # awk '{if ($1!="*vg_root*" || $1!="UUID*" || $1!="^$" || $1!="^#" || $3!="proc" || $3!="sysfs" || $3!="tmpfs" || $3!="devpts" || $4!="*nosuid*"){ $4=$4 ",nosuid"; print}}' /tmp/fstab_bk
# Commented Line followed,nosuid by empty line
/dev/mapper/vg_root-lv_root / ext4 defaults,nosuid 1 2
UUID=STRING1 /boot ext4 defaults,nosuid 1 2
/dev/mapper/vg_root-lv_home /home ext4 defaults,nosuid 1 2
/dev/mapper/vg_root-lv_opt /opt ext4 defaults,nosuid 1 2
# Commented Line followed,nosuid by empty line
   ,nosuid
/dev/mapper/vg_root-lv_tmp /tmp ext4 defaults,noexec,nosuid 1 2
/dev/mapper/vg_root-lv_usr /usr ext4 defaults,nosuid 1 2
/dev/mapper/vg_root-lv_var /var ext4 defaults,nosuid 1 2
/dev/mapper/vg_root-lv_swap swap swap defaults,nosuid 1 2
tmpfs /dev/shm tmpfs nodev,nosuid,noexec,nosuid 0 0
devpts /dev/pts devpts STRING2,nosuid 0 0
sysfs /sys sysfs defaults,nosuid 1 2
proc /proc proc defaults,nosuid 1 2
/tmp /var/tmp none bind,nodev,nosuid,noexec,nosuid 0 0
/dest1 /MP1 ext4 defaults,nodev,nosuid 1 2
/dest2 /MP2 ext3 defaults,nosuid 1 2
# Commented Line followed,nosuid by empty line
   ,nosuid
/dest3 /MP3 ext4 defaults,nosuid 1 2
at present , I can see that the conditionals are completely ignored.
 
Old 02-28-2019, 12:22 PM   #7
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,923

Rep: Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319
I would rather try the following:
Code:
awk ' /vg_root/ { continue }
      /UUID/ { continue }
# all similar conditions comes here
     { $4=$4 ",nosuid"; print}'
but it is not tested, and probably I misunderstood something. (this is only a tip to see a different approach, because I did not really catch what do you need)

Last edited by pan64; 02-28-2019 at 12:24 PM.
 
Old 02-28-2019, 12:41 PM   #8
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420

Original Poster
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
@pan64, Thanks for your attention.

Gave a quick try and got an error.
Code:
 # awk ' /vg_root/ { continue }
/UUID/ { continue }
> /nosuid/ { continue }
> /"^$"/ { continue } 
> { $4=$4 ",nosuid"; print}' /tmp/fstab_bk
awk: cmd. line:1: error: `continue' is not allowed outside a loop
awk: cmd. line:1: error: `continue' is not allowed outside a loop
If you can help with specifics, I have posted my original/target file and the intended result I am expecting. I am looking for a short one liner kind of thing and the fact that I came close at my first attempt with sed makes me hopeful that it's possible. I shall dig more on awk, but if I can get more pointers that'd be great.
 
Old 02-28-2019, 11:37 PM   #9
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420

Original Poster
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
attempt with if-then-else

So before I dig deeper into awk for a possible solution, I wanted to know whether a brutish approach works..
This is working -

Code:
#cat /tmp/fstab_bk | while read line; do echo $line; if [[ $line =~ .*vg_root.*  ||  $line =~ .*UUID.* ||  $line =~ .*^#.*  || $line =~ .*^$.*  ||  $line =~ .*nosuid.* || $line =~ .*proc.*  || $line =~ .*sysfs.*  ||  $line =~ .*devpts.* ]]; then echo $line >> /tmp/fstab_bk_bk; else echo $line | sed 's/defaults/defaults,nosuid/' >> /tmp/fstab_bk_bk;fi; done
comparison of input & output -

Code:
# sdiff /tmp/fstab_bk /tmp/fstab_bk_bk
# Commented Line followed by empty line                         # Commented Line followed by empty line
/dev/mapper/vg_root-lv_root     /       ext4    defaults 1 2  | /dev/mapper/vg_root-lv_root / ext4 defaults 1 2
UUID=STRING1       /boot   ext4    defaults 1 2               | UUID=STRING1 /boot ext4 defaults 1 2
/dev/mapper/vg_root-lv_home     /home   ext4    defaults 1 2  | /dev/mapper/vg_root-lv_home /home ext4 defaults 1 2
/dev/mapper/vg_root-lv_opt      /opt    ext4    defaults 1 2  | /dev/mapper/vg_root-lv_opt /opt ext4 defaults 1 2
# Commented Line followed by empty line                         # Commented Line followed by empty line

/dev/mapper/vg_root-lv_tmp      /tmp    ext4    defaults,noex | /dev/mapper/vg_root-lv_tmp /tmp ext4 defaults,noexec 1 2
/dev/mapper/vg_root-lv_usr      /usr    ext4    defaults 1 2  | /dev/mapper/vg_root-lv_usr /usr ext4 defaults 1 2
/dev/mapper/vg_root-lv_var      /var    ext4    defaults 1 2  | /dev/mapper/vg_root-lv_var /var ext4 defaults 1 2
/dev/mapper/vg_root-lv_swap     swap    swap    defaults 1 2  | /dev/mapper/vg_root-lv_swap swap swap defaults 1 2
tmpfs   /dev/shm        tmpfs   nodev,nosuid,noexec     0     | tmpfs /dev/shm tmpfs nodev,nosuid,noexec 0 0
devpts  /dev/pts        devpts  STRING2  0       0            | devpts /dev/pts devpts STRING2 0 0
sysfs   /sys    sysfs   defaults 1 2                          | sysfs /sys sysfs defaults 1 2
proc    /proc   proc    defaults 1 2                          | proc /proc proc defaults 1 2
/tmp    /var/tmp        none    bind,nodev,nosuid,noexec    0 | /tmp /var/tmp none bind,nodev,nosuid,noexec 0 0
/dest1  /MP1    ext4    defaults,nodev 1 2                    | /dest1 /MP1 ext4 defaults,nosuid,nodev 1 2
/dest2         /MP2      ext3    defaults 1 2                 | /dest2 /MP2 ext3 defaults,nosuid 1 2
# Commented Line followed by empty line                         # Commented Line followed by empty line

/dest3           /MP3                  ext4    defaults       | /dest3 /MP3 ext4 defaults,nosuid 1 2
Right now, the spacing between words are not being conserved. However, syntactically the output looks okay.
 
Old 03-01-2019, 12:31 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,923

Rep: Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319
Quote:
Originally Posted by Honest Abe View Post
@pan64, Thanks for your attention.

Gave a quick try and got an error.
Code:
 # awk ' /vg_root/ { continue }
/UUID/ { continue }
> /nosuid/ { continue }
> /"^$"/ { continue } 
> { $4=$4 ",nosuid"; print}' /tmp/fstab_bk
awk: cmd. line:1: error: `continue' is not allowed outside a loop
awk: cmd. line:1: error: `continue' is not allowed outside a loop
If you can help with specifics, I have posted my original/target file and the intended result I am expecting. I am looking for a short one liner kind of thing and the fact that I came close at my first attempt with sed makes me hopeful that it's possible. I shall dig more on awk, but if I can get more pointers that'd be great.
Yes, that was my mistake. It is next instead of continue. Sorry.
Also if you want to check empty lines you can write:
Code:
/^$/ { next } # << no " required
# or
length == 0 { next }
In sed you can do the same:
Code:
sed '/nosuid/n; /vg_root/n; /^$/n  ..... s/defaults/defaults,nosuid/'
 
Old 03-01-2019, 01:08 AM   #11
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
ok, i didn't read all of it, but allow me this one comment:
whenever i see a thread title "use sed to accomplish this-n-that"
my first thought is: "But is sed the right tool for the job?"
________________________
Quote:
Originally Posted by berndbausch View Post
Use double quotes instead. In my mother tongue, Gänsefüßchen (much cuter, I think). Try this:
Code:
i=123
echo ‘$i’
echo “$i”
Gänsefüßchen!
but something's off with your formatting.
consider this:
Code:
i=123
echo ‘$i’
echo '$i'
echo “$i”
echo "$i"
 
Old 03-01-2019, 02:52 AM   #12
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by ondoho View Post
ok, i didn't read all of it, but allow me this one comment:
whenever i see a thread title "use sed to accomplish this-n-that"
my first thought is: "But is sed the right tool for the job?"
________________________

Gänsefüßchen!
but something's off with your formatting.
consider this:
Code:
i=123
echo ‘$i’
echo '$i'
echo “$i”
echo "$i"
That's probably Windows and/or Firefox mangling my Gänsefüßchen.

And sed is not the right tool here, true.
 
Old 03-01-2019, 12:09 PM   #13
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420

Original Poster
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
Quote:
Originally Posted by pan64 View Post
Yes, that was my mistake. It is next instead of continue. Sorry.
Also if you want to check empty lines you can write:
Code:
/^$/ { next } # << no " required
# or
length == 0 { next }
This works..


Code:
# awk ' /vg_root/ { next } 
> /UUID/ { next }
> /^#/ { next }
> /^$/ { next }
> /sysfs/ { next }
> /proc/ { next }
> /tmpfs/ { next }
> /devpts/ { next }
> { $4=$4 ",nosuid"; print}' /tmp/fstab_bk
/tmp /var/tmp none bind,nodev,nosuid,noexec,nosuid 0 0
/dest1 /MP1 ext4 defaults,nodev,nosuid 1 2
/dest2 /MP2 ext3 defaults,nosuid 1 2
/dest3 /MP3 ext4 defaults,nosuid 1 2
Quote:
In sed you can do the same:
Code:
sed '/nosuid/n; /vg_root/n; /^$/n  ..... s/defaults/defaults,nosuid/'
Actually, if you see my approach I was trying to get this done within a loop. Thanks for direction.

Last edited by Honest Abe; 03-01-2019 at 12:12 PM.
 
Old 03-02-2019, 02:19 AM   #14
Honest Abe
Member
 
Registered: May 2018
Distribution: CentOS 7, OpenSUSE 15
Posts: 420

Original Poster
Blog Entries: 1

Rep: Reputation: 202Reputation: 202Reputation: 202
SED

Quote:
Originally Posted by pan64 View Post
In sed you can do the same:
Code:
sed '/nosuid/n; /vg_root/n; /^$/n  ..... s/defaults/defaults,nosuid/'
I think this needs some work with respect to pattern matching -

Code:
# sed '/*nosuid*/n; /\/dev\/mapper\/vg_root*/n; /^$/n; /^#/n; /UUID*/n; /*sysfs*/n; /*proc*/n; /*tmp*/n; /*devpts*/n; s/defaults/defaults.nosuid/' /tmp/fstab_bk
# Commented Line followed by empty line
/dev/mapper/vg_root-lv_root     /       ext4    defaults.nosuid 1 2
UUID=STRING1       /boot   ext4    defaults 1 2
/dev/mapper/vg_root-lv_home     /home   ext4    defaults.nosuid 1 2
dev/mapper/vg_root-lv_opt      /opt    ext4    defaults 1 2
# Commented Line followed by empty line[/B]

[B]/dev/mapper/vg_root-lv_tmp      /tmp    ext4    defaults,noexec         1       2
/dev/mapper/vg_root-lv_usr      /usr    ext4    defaults.nosuid 1 2
/dev/mapper/vg_root-lv_var      /var    ext4    defaults 1 2
/dev/mapper/vg_root-lv_swap     swap    swap    defaults.nosuid 1 2
tmpfs   /dev/shm        tmpfs   nodev,nosuid,noexec     0       0
devpts  /dev/pts        devpts  STRING2  0       0
sysfs   /sys    sysfs   defaults.nosuid 1 2
proc    /proc   proc    defaults.nosuid 1 2
/tmp    /var/tmp        none    bind,nodev,nosuid,noexec    0      0
/dest1  /MP1    ext4    defaults.nosuid,nodev 1 2
/dest2         /MP2      ext3    defaults.nosuid 1 2
# Commented Line followed by empty line

/dest3           /MP3                  ext4    defaults.nosuid        1       2
Bold lines are somehow not matching my expected results, whereas the blue lines are expected.
[The dot (.) in the replacement string was a typo, but I left it as it is, since it's all being done on a test file ]

Here is one more attempt, different regex ..
Code:
# sed '/nosuid/n; /vg_root/n; /^$/n; /^#/n; /UUID/n; /sysfs/n; /proc/n; /tmp/n; /devpts/n; s/defaults/defaults.nosuid/' /tmp/fstab_bk
# Commented Line followed by empty line
/dev/mapper/vg_root-lv_root     /       ext4    defaults.nosuid 1 2
UUID=STRING1       /boot   ext4    defaults 1 2
/dev/mapper/vg_root-lv_home     /home   ext4    defaults.nosuid 1 2
/dev/mapper/vg_root-lv_opt      /opt    ext4    defaults 1 2
# Commented Line followed by empty line

/dev/mapper/vg_root-lv_tmp      /tmp    ext4    defaults,noexec         1       2
/dev/mapper/vg_root-lv_usr      /usr    ext4    defaults.nosuid 1 2
/dev/mapper/vg_root-lv_var      /var    ext4    defaults 1 2
/dev/mapper/vg_root-lv_swap     swap    swap    defaults.nosuid 1 2
tmpfs   /dev/shm        tmpfs   nodev,nosuid,noexec     0       0
devpts  /dev/pts        devpts  STRING2  0       0
sysfs   /sys    sysfs   defaults.nosuid 1 2
proc    /proc   proc    defaults 1 2
/tmp    /var/tmp        none    bind,nodev,nosuid,noexec    0      0
/dest1  /MP1    ext4    defaults.nosuid,nodev 1 2
/dest2         /MP2      ext3    defaults.nosuid 1 2
# Commented Line followed by empty line

/dest3           /MP3                  ext4    defaults.nosuid        1       2
 
Old 03-02-2019, 12:38 PM   #15
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,923

Rep: Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319Reputation: 7319
sorry, I'm trying to understand. * in those regexps are not ok. Also the dot in defaults.nosuid looks strange.
For me it looks like that sed works properly, just the expression is not the one you really need.
The logic is to "skip" all the lines which should not be changed:
Code:
/sysfs/n;
and finally substitute defaults. I was thinking about replacing n to {p;d}, that will lead to something like this:
Code:
sed '/UUID/{p;d};/^#/{p;d};/^$/{p;d};/sysfs/{p;d};/proc/{p;d};/tmpfs/{p;d};/devpts/{p;d};s/defaults/defaults,nosuid/'
but I'm unsure at this moment
 
  


Reply



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
[SOLVED] SED Multiline edit -- Quit After First Match/Edit RandyTech Linux - Newbie 9 06-09-2014 03:15 AM
[SOLVED] Help Edit the /etc/fstab specifically the dump and fsck options jollibee Linux - Newbie 3 07-16-2009 11:30 PM
Why unable to mount my nas in fstab get "mount error(5) Input/output error fi5ban Linux - Networking 0 04-01-2009 10:42 AM
fstab problem: mount: can't find dvd in /etc/fstab or /etc/mtab Nikon01 Slackware 5 11-17-2006 06:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:33 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
Open Source Consulting | Domain Registration