How to delete from configuration file variable that not equal to 100
Clash 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
.
.
linux shell-script text-processing sed perl
add a comment |Â
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
.
.
linux shell-script text-processing sed perl
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 withsed
.
â slmâ¦
Aug 8 at 11:24
add a comment |Â
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
.
.
linux shell-script text-processing sed perl
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
linux shell-script text-processing sed perl
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 withsed
.
â slmâ¦
Aug 8 at 11:24
add a comment |Â
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 withsed
.
â 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
add a comment |Â
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.
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
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
$ 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.
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
add a comment |Â
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.
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
add a comment |Â
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.
$ 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.
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
add a comment |Â
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
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%2f461225%2fhow-to-delete-from-configuration-file-variable-that-not-equal-to-100%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
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