How to delete from configuration file variable that not equal to 100

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












How to delete from configuration file the variable/s hadoop.tasklog.totalLogFileSize that are not equal to 100



example



more file.conf

hadoop.tasklog.totalLogFileSize=107
hadoop.tasklog.totalLogFileSize=10
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.totalLogFileSize=189
hadoop.tasklog.totalLogFileSize=104
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.


expected output



more file.conf

hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.









share|improve this question



















  • 1




    Why do you make config file changes using scripts to start with?
    – Kusalananda
    Aug 8 at 8:50










  • we are working on log4j configuration , and some old conf comes with old values
    – yael
    Aug 8 at 8:51






  • 2




    when asking question, please also add what you have tried yourself to solve this.. this is not a free coding service site.. you have asked and received lots of answers on text processing questions, by now you should be able to at least make an attempt to solve it..
    – Sundeep
    Aug 8 at 8:56










  • @yael - you're clearly working on Hadoop, is this vanilla apache, Hortonworks or Cloudera? There are better methods to manage these than editing the files with sed.
    – slm♦
    Aug 8 at 11:24














up vote
-1
down vote

favorite












How to delete from configuration file the variable/s hadoop.tasklog.totalLogFileSize that are not equal to 100



example



more file.conf

hadoop.tasklog.totalLogFileSize=107
hadoop.tasklog.totalLogFileSize=10
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.totalLogFileSize=189
hadoop.tasklog.totalLogFileSize=104
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.


expected output



more file.conf

hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.









share|improve this question



















  • 1




    Why do you make config file changes using scripts to start with?
    – Kusalananda
    Aug 8 at 8:50










  • we are working on log4j configuration , and some old conf comes with old values
    – yael
    Aug 8 at 8:51






  • 2




    when asking question, please also add what you have tried yourself to solve this.. this is not a free coding service site.. you have asked and received lots of answers on text processing questions, by now you should be able to at least make an attempt to solve it..
    – Sundeep
    Aug 8 at 8:56










  • @yael - you're clearly working on Hadoop, is this vanilla apache, Hortonworks or Cloudera? There are better methods to manage these than editing the files with sed.
    – slm♦
    Aug 8 at 11:24












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











How to delete from configuration file the variable/s hadoop.tasklog.totalLogFileSize that are not equal to 100



example



more file.conf

hadoop.tasklog.totalLogFileSize=107
hadoop.tasklog.totalLogFileSize=10
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.totalLogFileSize=189
hadoop.tasklog.totalLogFileSize=104
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.


expected output



more file.conf

hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.









share|improve this question















How to delete from configuration file the variable/s hadoop.tasklog.totalLogFileSize that are not equal to 100



example



more file.conf

hadoop.tasklog.totalLogFileSize=107
hadoop.tasklog.totalLogFileSize=10
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.totalLogFileSize=189
hadoop.tasklog.totalLogFileSize=104
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.


expected output



more file.conf

hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12
.
.






linux shell-script text-processing sed perl






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 8 at 9:53









Jeff Schaller

32.4k849110




32.4k849110










asked Aug 8 at 8:38









yael

2,0341145




2,0341145







  • 1




    Why do you make config file changes using scripts to start with?
    – Kusalananda
    Aug 8 at 8:50










  • we are working on log4j configuration , and some old conf comes with old values
    – yael
    Aug 8 at 8:51






  • 2




    when asking question, please also add what you have tried yourself to solve this.. this is not a free coding service site.. you have asked and received lots of answers on text processing questions, by now you should be able to at least make an attempt to solve it..
    – Sundeep
    Aug 8 at 8:56










  • @yael - you're clearly working on Hadoop, is this vanilla apache, Hortonworks or Cloudera? There are better methods to manage these than editing the files with sed.
    – slm♦
    Aug 8 at 11:24












  • 1




    Why do you make config file changes using scripts to start with?
    – Kusalananda
    Aug 8 at 8:50










  • we are working on log4j configuration , and some old conf comes with old values
    – yael
    Aug 8 at 8:51






  • 2




    when asking question, please also add what you have tried yourself to solve this.. this is not a free coding service site.. you have asked and received lots of answers on text processing questions, by now you should be able to at least make an attempt to solve it..
    – Sundeep
    Aug 8 at 8:56










  • @yael - you're clearly working on Hadoop, is this vanilla apache, Hortonworks or Cloudera? There are better methods to manage these than editing the files with sed.
    – slm♦
    Aug 8 at 11:24







1




1




Why do you make config file changes using scripts to start with?
– Kusalananda
Aug 8 at 8:50




Why do you make config file changes using scripts to start with?
– Kusalananda
Aug 8 at 8:50












we are working on log4j configuration , and some old conf comes with old values
– yael
Aug 8 at 8:51




we are working on log4j configuration , and some old conf comes with old values
– yael
Aug 8 at 8:51




2




2




when asking question, please also add what you have tried yourself to solve this.. this is not a free coding service site.. you have asked and received lots of answers on text processing questions, by now you should be able to at least make an attempt to solve it..
– Sundeep
Aug 8 at 8:56




when asking question, please also add what you have tried yourself to solve this.. this is not a free coding service site.. you have asked and received lots of answers on text processing questions, by now you should be able to at least make an attempt to solve it..
– Sundeep
Aug 8 at 8:56












@yael - you're clearly working on Hadoop, is this vanilla apache, Hortonworks or Cloudera? There are better methods to manage these than editing the files with sed.
– slm♦
Aug 8 at 11:24




@yael - you're clearly working on Hadoop, is this vanilla apache, Hortonworks or Cloudera? There are better methods to manage these than editing the files with sed.
– slm♦
Aug 8 at 11:24










1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










$ awk -F= '/hadoop.tasklog.totalLogFileSize/ && $2 != 100 next 1' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This treats the file as =-delimited fields. If a line matches the given pattern, and if the number after = (i.e. the second field) is not 100, then the line is skipped and not outputted. All other lines are outputted by the trailing 1 at the end of the program (which could be replaced by print ).



Using sed:



$ sed '/hadoop.tasklog.totalLogFileSize/ /=100$/!d; ' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This outputs all lines, but when a line matches the given pattern, and then does not match =100 at the end of the line, it is deleted from the input.






share|improve this answer






















  • this is very great idea to do it with awk , but actually I tag sed and perl one liner since we want the option "sed -i" or "perl -i" to edit the file , with awk we need to copy the file that created to the source file , and we want to avoid that ( +1 for your effort )
    – yael
    Aug 8 at 8:49











  • @yael See updated answer.
    – Kusalananda
    Aug 8 at 8:53










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%2f461225%2fhow-to-delete-from-configuration-file-variable-that-not-equal-to-100%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
1
down vote



accepted










$ awk -F= '/hadoop.tasklog.totalLogFileSize/ && $2 != 100 next 1' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This treats the file as =-delimited fields. If a line matches the given pattern, and if the number after = (i.e. the second field) is not 100, then the line is skipped and not outputted. All other lines are outputted by the trailing 1 at the end of the program (which could be replaced by print ).



Using sed:



$ sed '/hadoop.tasklog.totalLogFileSize/ /=100$/!d; ' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This outputs all lines, but when a line matches the given pattern, and then does not match =100 at the end of the line, it is deleted from the input.






share|improve this answer






















  • this is very great idea to do it with awk , but actually I tag sed and perl one liner since we want the option "sed -i" or "perl -i" to edit the file , with awk we need to copy the file that created to the source file , and we want to avoid that ( +1 for your effort )
    – yael
    Aug 8 at 8:49











  • @yael See updated answer.
    – Kusalananda
    Aug 8 at 8:53














up vote
1
down vote



accepted










$ awk -F= '/hadoop.tasklog.totalLogFileSize/ && $2 != 100 next 1' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This treats the file as =-delimited fields. If a line matches the given pattern, and if the number after = (i.e. the second field) is not 100, then the line is skipped and not outputted. All other lines are outputted by the trailing 1 at the end of the program (which could be replaced by print ).



Using sed:



$ sed '/hadoop.tasklog.totalLogFileSize/ /=100$/!d; ' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This outputs all lines, but when a line matches the given pattern, and then does not match =100 at the end of the line, it is deleted from the input.






share|improve this answer






















  • this is very great idea to do it with awk , but actually I tag sed and perl one liner since we want the option "sed -i" or "perl -i" to edit the file , with awk we need to copy the file that created to the source file , and we want to avoid that ( +1 for your effort )
    – yael
    Aug 8 at 8:49











  • @yael See updated answer.
    – Kusalananda
    Aug 8 at 8:53












up vote
1
down vote



accepted







up vote
1
down vote



accepted






$ awk -F= '/hadoop.tasklog.totalLogFileSize/ && $2 != 100 next 1' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This treats the file as =-delimited fields. If a line matches the given pattern, and if the number after = (i.e. the second field) is not 100, then the line is skipped and not outputted. All other lines are outputted by the trailing 1 at the end of the program (which could be replaced by print ).



Using sed:



$ sed '/hadoop.tasklog.totalLogFileSize/ /=100$/!d; ' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This outputs all lines, but when a line matches the given pattern, and then does not match =100 at the end of the line, it is deleted from the input.






share|improve this answer














$ awk -F= '/hadoop.tasklog.totalLogFileSize/ && $2 != 100 next 1' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This treats the file as =-delimited fields. If a line matches the given pattern, and if the number after = (i.e. the second field) is not 100, then the line is skipped and not outputted. All other lines are outputted by the trailing 1 at the end of the program (which could be replaced by print ).



Using sed:



$ sed '/hadoop.tasklog.totalLogFileSize/ /=100$/!d; ' file
hadoop.tasklog.totalLogFileSize=100
hadoop.tasklog.purgeLogSplits=true
hadoop.tasklog.logsRetainHours=12


This outputs all lines, but when a line matches the given pattern, and then does not match =100 at the end of the line, it is deleted from the input.







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 8 at 8:53

























answered Aug 8 at 8:45









Kusalananda

106k14209327




106k14209327











  • this is very great idea to do it with awk , but actually I tag sed and perl one liner since we want the option "sed -i" or "perl -i" to edit the file , with awk we need to copy the file that created to the source file , and we want to avoid that ( +1 for your effort )
    – yael
    Aug 8 at 8:49











  • @yael See updated answer.
    – Kusalananda
    Aug 8 at 8:53
















  • this is very great idea to do it with awk , but actually I tag sed and perl one liner since we want the option "sed -i" or "perl -i" to edit the file , with awk we need to copy the file that created to the source file , and we want to avoid that ( +1 for your effort )
    – yael
    Aug 8 at 8:49











  • @yael See updated answer.
    – Kusalananda
    Aug 8 at 8:53















this is very great idea to do it with awk , but actually I tag sed and perl one liner since we want the option "sed -i" or "perl -i" to edit the file , with awk we need to copy the file that created to the source file , and we want to avoid that ( +1 for your effort )
– yael
Aug 8 at 8:49





this is very great idea to do it with awk , but actually I tag sed and perl one liner since we want the option "sed -i" or "perl -i" to edit the file , with awk we need to copy the file that created to the source file , and we want to avoid that ( +1 for your effort )
– yael
Aug 8 at 8:49













@yael See updated answer.
– Kusalananda
Aug 8 at 8:53




@yael See updated answer.
– Kusalananda
Aug 8 at 8:53

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f461225%2fhow-to-delete-from-configuration-file-variable-that-not-equal-to-100%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?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay