sed + remove the â#â character in case line appears
Clash Royale CLAN TAG#URR8PPP
up vote
1
down vote
favorite
we have the following file:
cat graphite-web.conf
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
# Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
what is the best approach to remove the # before the line "Require all granted"
- the "#" character not in the beginning of the line
expected output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
linux text-processing awk sed perl
add a comment |Â
up vote
1
down vote
favorite
we have the following file:
cat graphite-web.conf
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
# Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
what is the best approach to remove the # before the line "Require all granted"
- the "#" character not in the beginning of the line
expected output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
linux text-processing awk sed perl
yes both are need to update
â yael
Oct 29 '17 at 20:02
It looks to me like the#
is at the beginning of the line (in the entire example); how do the lines change in the output if that's the case?
â Jeff Schaller
Oct 29 '17 at 20:04
the # not in the begging , I saw the file and this # is couple spaces after the begging
â yael
Oct 29 '17 at 20:05
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
we have the following file:
cat graphite-web.conf
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
# Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
what is the best approach to remove the # before the line "Require all granted"
- the "#" character not in the beginning of the line
expected output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
linux text-processing awk sed perl
we have the following file:
cat graphite-web.conf
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
# Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
what is the best approach to remove the # before the line "Require all granted"
- the "#" character not in the beginning of the line
expected output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
# Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
linux text-processing awk sed perl
edited Oct 29 '17 at 20:04
Jeff Schaller
32.1k849109
32.1k849109
asked Oct 29 '17 at 19:40
yael
2,0251145
2,0251145
yes both are need to update
â yael
Oct 29 '17 at 20:02
It looks to me like the#
is at the beginning of the line (in the entire example); how do the lines change in the output if that's the case?
â Jeff Schaller
Oct 29 '17 at 20:04
the # not in the begging , I saw the file and this # is couple spaces after the begging
â yael
Oct 29 '17 at 20:05
add a comment |Â
yes both are need to update
â yael
Oct 29 '17 at 20:02
It looks to me like the#
is at the beginning of the line (in the entire example); how do the lines change in the output if that's the case?
â Jeff Schaller
Oct 29 '17 at 20:04
the # not in the begging , I saw the file and this # is couple spaces after the begging
â yael
Oct 29 '17 at 20:05
yes both are need to update
â yael
Oct 29 '17 at 20:02
yes both are need to update
â yael
Oct 29 '17 at 20:02
It looks to me like the
#
is at the beginning of the line (in the entire example); how do the lines change in the output if that's the case?â Jeff Schaller
Oct 29 '17 at 20:04
It looks to me like the
#
is at the beginning of the line (in the entire example); how do the lines change in the output if that's the case?â Jeff Schaller
Oct 29 '17 at 20:04
the # not in the begging , I saw the file and this # is couple spaces after the begging
â yael
Oct 29 '17 at 20:05
the # not in the begging , I saw the file and this # is couple spaces after the begging
â yael
Oct 29 '17 at 20:05
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
3
down vote
accepted
sed solution:
sed 's/#([[:space:]]*Require all granted)/ 1/' graphite-web.conf
The output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
To edit the file inplace - add -i
option:
sed -i ....
how to use the flag -i in the sed syntax ? ( we want to edit the file in the command and not copy it )
â yael
Oct 29 '17 at 20:01
@yael, see my note
â RomanPerekhrest
Oct 29 '17 at 20:02
sed -i 's/#([[:space:]]*Require all granted)/ 1/' /tmp/install_zone/GRAPHITE/package/files/inst_files/graphite-web.conf sed: -e expression #1, char 41: invalid reference 1 on `s' command's RHS
â yael
Oct 29 '17 at 20:03
any suggestion regarding the "-i" in the sed ?
â yael
Oct 29 '17 at 20:07
@yael, you have used my approach in wrong way: parenthesis should be escaped.(
â RomanPerekhrest
Oct 29 '17 at 20:08
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
sed solution:
sed 's/#([[:space:]]*Require all granted)/ 1/' graphite-web.conf
The output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
To edit the file inplace - add -i
option:
sed -i ....
how to use the flag -i in the sed syntax ? ( we want to edit the file in the command and not copy it )
â yael
Oct 29 '17 at 20:01
@yael, see my note
â RomanPerekhrest
Oct 29 '17 at 20:02
sed -i 's/#([[:space:]]*Require all granted)/ 1/' /tmp/install_zone/GRAPHITE/package/files/inst_files/graphite-web.conf sed: -e expression #1, char 41: invalid reference 1 on `s' command's RHS
â yael
Oct 29 '17 at 20:03
any suggestion regarding the "-i" in the sed ?
â yael
Oct 29 '17 at 20:07
@yael, you have used my approach in wrong way: parenthesis should be escaped.(
â RomanPerekhrest
Oct 29 '17 at 20:08
add a comment |Â
up vote
3
down vote
accepted
sed solution:
sed 's/#([[:space:]]*Require all granted)/ 1/' graphite-web.conf
The output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
To edit the file inplace - add -i
option:
sed -i ....
how to use the flag -i in the sed syntax ? ( we want to edit the file in the command and not copy it )
â yael
Oct 29 '17 at 20:01
@yael, see my note
â RomanPerekhrest
Oct 29 '17 at 20:02
sed -i 's/#([[:space:]]*Require all granted)/ 1/' /tmp/install_zone/GRAPHITE/package/files/inst_files/graphite-web.conf sed: -e expression #1, char 41: invalid reference 1 on `s' command's RHS
â yael
Oct 29 '17 at 20:03
any suggestion regarding the "-i" in the sed ?
â yael
Oct 29 '17 at 20:07
@yael, you have used my approach in wrong way: parenthesis should be escaped.(
â RomanPerekhrest
Oct 29 '17 at 20:08
add a comment |Â
up vote
3
down vote
accepted
up vote
3
down vote
accepted
sed solution:
sed 's/#([[:space:]]*Require all granted)/ 1/' graphite-web.conf
The output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
To edit the file inplace - add -i
option:
sed -i ....
sed solution:
sed 's/#([[:space:]]*Require all granted)/ 1/' graphite-web.conf
The output:
#<IfModule mod_authz_core.c>
# # Apache 2.4
# Require local
# Order Allow,Deny
# Allow from All
Require all granted
#</IfModule>
#<IfModule !mod_authz_core.c>
# # Apache 2.2
Require all granted
# Order Allow,Deny
# Deny from all
# Allow from All
# Allow from ::1
#</IfModule>
To edit the file inplace - add -i
option:
sed -i ....
edited Oct 29 '17 at 20:02
answered Oct 29 '17 at 19:52
RomanPerekhrest
22.5k12145
22.5k12145
how to use the flag -i in the sed syntax ? ( we want to edit the file in the command and not copy it )
â yael
Oct 29 '17 at 20:01
@yael, see my note
â RomanPerekhrest
Oct 29 '17 at 20:02
sed -i 's/#([[:space:]]*Require all granted)/ 1/' /tmp/install_zone/GRAPHITE/package/files/inst_files/graphite-web.conf sed: -e expression #1, char 41: invalid reference 1 on `s' command's RHS
â yael
Oct 29 '17 at 20:03
any suggestion regarding the "-i" in the sed ?
â yael
Oct 29 '17 at 20:07
@yael, you have used my approach in wrong way: parenthesis should be escaped.(
â RomanPerekhrest
Oct 29 '17 at 20:08
add a comment |Â
how to use the flag -i in the sed syntax ? ( we want to edit the file in the command and not copy it )
â yael
Oct 29 '17 at 20:01
@yael, see my note
â RomanPerekhrest
Oct 29 '17 at 20:02
sed -i 's/#([[:space:]]*Require all granted)/ 1/' /tmp/install_zone/GRAPHITE/package/files/inst_files/graphite-web.conf sed: -e expression #1, char 41: invalid reference 1 on `s' command's RHS
â yael
Oct 29 '17 at 20:03
any suggestion regarding the "-i" in the sed ?
â yael
Oct 29 '17 at 20:07
@yael, you have used my approach in wrong way: parenthesis should be escaped.(
â RomanPerekhrest
Oct 29 '17 at 20:08
how to use the flag -i in the sed syntax ? ( we want to edit the file in the command and not copy it )
â yael
Oct 29 '17 at 20:01
how to use the flag -i in the sed syntax ? ( we want to edit the file in the command and not copy it )
â yael
Oct 29 '17 at 20:01
@yael, see my note
â RomanPerekhrest
Oct 29 '17 at 20:02
@yael, see my note
â RomanPerekhrest
Oct 29 '17 at 20:02
sed -i 's/#([[:space:]]*Require all granted)/ 1/' /tmp/install_zone/GRAPHITE/package/files/inst_files/graphite-web.conf sed: -e expression #1, char 41: invalid reference 1 on `s' command's RHS
â yael
Oct 29 '17 at 20:03
sed -i 's/#([[:space:]]*Require all granted)/ 1/' /tmp/install_zone/GRAPHITE/package/files/inst_files/graphite-web.conf sed: -e expression #1, char 41: invalid reference 1 on `s' command's RHS
â yael
Oct 29 '17 at 20:03
any suggestion regarding the "-i" in the sed ?
â yael
Oct 29 '17 at 20:07
any suggestion regarding the "-i" in the sed ?
â yael
Oct 29 '17 at 20:07
@yael, you have used my approach in wrong way: parenthesis should be escaped.
(
â RomanPerekhrest
Oct 29 '17 at 20:08
@yael, you have used my approach in wrong way: parenthesis should be escaped.
(
â RomanPerekhrest
Oct 29 '17 at 20:08
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
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f401276%2fsed-remove-the-character-in-case-line-appears%23new-answer', 'question_page');
);
Post as a guest
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
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
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
yes both are need to update
â yael
Oct 29 '17 at 20:02
It looks to me like the
#
is at the beginning of the line (in the entire example); how do the lines change in the output if that's the case?â Jeff Schaller
Oct 29 '17 at 20:04
the # not in the begging , I saw the file and this # is couple spaces after the begging
â yael
Oct 29 '17 at 20:05