How do I comment lines in fstab using sed?
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I want to comment certain lines in fstab
using sed
command. The following are the lines I need to comment:
172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
I tried using this command but it didn't work:
sed -i '/172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
sed -i '/172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
linux sed fstab
add a comment |
up vote
0
down vote
favorite
I want to comment certain lines in fstab
using sed
command. The following are the lines I need to comment:
172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
I tried using this command but it didn't work:
sed -i '/172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
sed -i '/172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
linux sed fstab
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I want to comment certain lines in fstab
using sed
command. The following are the lines I need to comment:
172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
I tried using this command but it didn't work:
sed -i '/172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
sed -i '/172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
linux sed fstab
I want to comment certain lines in fstab
using sed
command. The following are the lines I need to comment:
172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp
I tried using this command but it didn't work:
sed -i '/172.0.0.1:/export/project/common /nfs/share nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
sed -i '/172.0.0.1:/export/project/share1 /nfs/shares1 nfs4 rw,bg,hard,nointr,rsize=131072,wsize=131072,proto=tcp /s/^/#/' /etc/fstab_test
linux sed fstab
linux sed fstab
edited Nov 18 at 9:30
Rui F Ribeiro
38.2k1475123
38.2k1475123
asked Jul 13 '16 at 3:43
NetMonkey2040
34
34
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
Try this,
sed -e '/[/]/common s/^/#/' /etc/fstab
sed -e '/[/]/share1 s/^/#/' /etc/fstab
Specifying this /[/]common/
will select only lines that contain /common.
If this works then replace -e
with -i
for executing the changing into the file.
You can do this with awk
awk '/[/]common/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
awk '/[/]share1/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
Specifying this /[/]common/ $0="#"$0
will chose those lines containing /common and place a # at the beginning of the line.
awk work like charm, but i have smalll query. when run awk command. it also comment all other shares which has common in them, is there a way to only comment common of specific project /project1/common
– NetMonkey2040
Jul 13 '16 at 4:38
you can select something which is unique on those line offstab
file.
– Mongrel
Jul 13 '16 at 4:58
if the full paths (either NFS remote or local mount point) are the only unique things on a line, then you'll have to use one of them. and remember to escape all/
s as/
.
– cas
Jul 13 '16 at 11:33
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
Try this,
sed -e '/[/]/common s/^/#/' /etc/fstab
sed -e '/[/]/share1 s/^/#/' /etc/fstab
Specifying this /[/]common/
will select only lines that contain /common.
If this works then replace -e
with -i
for executing the changing into the file.
You can do this with awk
awk '/[/]common/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
awk '/[/]share1/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
Specifying this /[/]common/ $0="#"$0
will chose those lines containing /common and place a # at the beginning of the line.
awk work like charm, but i have smalll query. when run awk command. it also comment all other shares which has common in them, is there a way to only comment common of specific project /project1/common
– NetMonkey2040
Jul 13 '16 at 4:38
you can select something which is unique on those line offstab
file.
– Mongrel
Jul 13 '16 at 4:58
if the full paths (either NFS remote or local mount point) are the only unique things on a line, then you'll have to use one of them. and remember to escape all/
s as/
.
– cas
Jul 13 '16 at 11:33
add a comment |
up vote
1
down vote
accepted
Try this,
sed -e '/[/]/common s/^/#/' /etc/fstab
sed -e '/[/]/share1 s/^/#/' /etc/fstab
Specifying this /[/]common/
will select only lines that contain /common.
If this works then replace -e
with -i
for executing the changing into the file.
You can do this with awk
awk '/[/]common/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
awk '/[/]share1/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
Specifying this /[/]common/ $0="#"$0
will chose those lines containing /common and place a # at the beginning of the line.
awk work like charm, but i have smalll query. when run awk command. it also comment all other shares which has common in them, is there a way to only comment common of specific project /project1/common
– NetMonkey2040
Jul 13 '16 at 4:38
you can select something which is unique on those line offstab
file.
– Mongrel
Jul 13 '16 at 4:58
if the full paths (either NFS remote or local mount point) are the only unique things on a line, then you'll have to use one of them. and remember to escape all/
s as/
.
– cas
Jul 13 '16 at 11:33
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
Try this,
sed -e '/[/]/common s/^/#/' /etc/fstab
sed -e '/[/]/share1 s/^/#/' /etc/fstab
Specifying this /[/]common/
will select only lines that contain /common.
If this works then replace -e
with -i
for executing the changing into the file.
You can do this with awk
awk '/[/]common/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
awk '/[/]share1/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
Specifying this /[/]common/ $0="#"$0
will chose those lines containing /common and place a # at the beginning of the line.
Try this,
sed -e '/[/]/common s/^/#/' /etc/fstab
sed -e '/[/]/share1 s/^/#/' /etc/fstab
Specifying this /[/]common/
will select only lines that contain /common.
If this works then replace -e
with -i
for executing the changing into the file.
You can do this with awk
awk '/[/]common/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
awk '/[/]share1/$0="#"$0 1' /etc/fstab >/etc/fstab.tmp && mv /etc/fstab.tmp /etc/fstab
Specifying this /[/]common/ $0="#"$0
will chose those lines containing /common and place a # at the beginning of the line.
edited Jul 13 '16 at 4:11
answered Jul 13 '16 at 3:58
Mongrel
2,04131344
2,04131344
awk work like charm, but i have smalll query. when run awk command. it also comment all other shares which has common in them, is there a way to only comment common of specific project /project1/common
– NetMonkey2040
Jul 13 '16 at 4:38
you can select something which is unique on those line offstab
file.
– Mongrel
Jul 13 '16 at 4:58
if the full paths (either NFS remote or local mount point) are the only unique things on a line, then you'll have to use one of them. and remember to escape all/
s as/
.
– cas
Jul 13 '16 at 11:33
add a comment |
awk work like charm, but i have smalll query. when run awk command. it also comment all other shares which has common in them, is there a way to only comment common of specific project /project1/common
– NetMonkey2040
Jul 13 '16 at 4:38
you can select something which is unique on those line offstab
file.
– Mongrel
Jul 13 '16 at 4:58
if the full paths (either NFS remote or local mount point) are the only unique things on a line, then you'll have to use one of them. and remember to escape all/
s as/
.
– cas
Jul 13 '16 at 11:33
awk work like charm, but i have smalll query. when run awk command. it also comment all other shares which has common in them, is there a way to only comment common of specific project /project1/common
– NetMonkey2040
Jul 13 '16 at 4:38
awk work like charm, but i have smalll query. when run awk command. it also comment all other shares which has common in them, is there a way to only comment common of specific project /project1/common
– NetMonkey2040
Jul 13 '16 at 4:38
you can select something which is unique on those line of
fstab
file.– Mongrel
Jul 13 '16 at 4:58
you can select something which is unique on those line of
fstab
file.– Mongrel
Jul 13 '16 at 4:58
if the full paths (either NFS remote or local mount point) are the only unique things on a line, then you'll have to use one of them. and remember to escape all
/
s as /
.– cas
Jul 13 '16 at 11:33
if the full paths (either NFS remote or local mount point) are the only unique things on a line, then you'll have to use one of them. and remember to escape all
/
s as /
.– cas
Jul 13 '16 at 11:33
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f295537%2fhow-do-i-comment-lines-in-fstab-using-sed%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown