sed + remove the “#” character in case line appears

The name of the pictureThe name of the pictureThe name of the pictureClash 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>






share|improve this question






















  • 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














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>






share|improve this question






















  • 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












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>






share|improve this question














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>








share|improve this question













share|improve this question




share|improve this question








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
















  • 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










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





share|improve this answer






















  • 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











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















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






























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





share|improve this answer






















  • 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















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





share|improve this answer






















  • 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













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





share|improve this answer














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






share|improve this answer














share|improve this answer



share|improve this answer








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

















  • 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


















 

draft saved


draft discarded















































 


draft saved


draft discarded














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













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Displaying single band from multi-band raster using QGIS

How many registers does an x86_64 CPU actually have?