How to add properties in the end of the two first lines with double quote?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
We want to add the following properties:
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M
in the two first lines that contain the word - HBASE_MASTER_OPTS
Example before change:
more ams-hbase-env-template.txt
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
Example after change (expected results):
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
What I did until now is that:
sed -i '/HBASE_MASTER_OPTS/ s/$/-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/' ams-hbase-env-template.txt
But this isn't right because:
We want the properties before the end of double quote.
Properties must be only on the first two lines that variable is HBASE_MASTER_OPTS.
In case properties are already in line, then it will not append again on any next time!
shell-script text-processing awk sed perl
add a comment |Â
up vote
3
down vote
favorite
We want to add the following properties:
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M
in the two first lines that contain the word - HBASE_MASTER_OPTS
Example before change:
more ams-hbase-env-template.txt
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
Example after change (expected results):
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
What I did until now is that:
sed -i '/HBASE_MASTER_OPTS/ s/$/-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/' ams-hbase-env-template.txt
But this isn't right because:
We want the properties before the end of double quote.
Properties must be only on the first two lines that variable is HBASE_MASTER_OPTS.
In case properties are already in line, then it will not append again on any next time!
shell-script text-processing awk sed perl
1
Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again? And, if such a line is encountered, would it still count as being one of the first two lines?
â Dirk Herrmann
Aug 13 at 22:41
1
regarding to Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again - YES I MEAN THAT
â yael
Aug 13 at 22:49
@yael Can you update your example (before + after) so that your point 3 is covered? It would be helpful if your example would reflect all the points that you need on what you're asking... Thanks!
â Filipe Brandenburger
Aug 15 at 5:46
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
We want to add the following properties:
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M
in the two first lines that contain the word - HBASE_MASTER_OPTS
Example before change:
more ams-hbase-env-template.txt
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
Example after change (expected results):
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
What I did until now is that:
sed -i '/HBASE_MASTER_OPTS/ s/$/-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/' ams-hbase-env-template.txt
But this isn't right because:
We want the properties before the end of double quote.
Properties must be only on the first two lines that variable is HBASE_MASTER_OPTS.
In case properties are already in line, then it will not append again on any next time!
shell-script text-processing awk sed perl
We want to add the following properties:
-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M
in the two first lines that contain the word - HBASE_MASTER_OPTS
Example before change:
more ams-hbase-env-template.txt
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
Example after change (expected results):
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=71 -XX:+UseCMSInitiatingOccupancyOnly -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=72 -XX:+UseCMSInitiatingOccupancyOnly"
export HBASE_MASTER_OPTS=" -XX:CMSInitiatingOccupancyFraction=73 -XX:+UseCMSInitiatingOccupancyOnly"
What I did until now is that:
sed -i '/HBASE_MASTER_OPTS/ s/$/-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/' ams-hbase-env-template.txt
But this isn't right because:
We want the properties before the end of double quote.
Properties must be only on the first two lines that variable is HBASE_MASTER_OPTS.
In case properties are already in line, then it will not append again on any next time!
shell-script text-processing awk sed perl
shell-script text-processing awk sed perl
edited Aug 20 at 13:30
GAD3R
22.8k154895
22.8k154895
asked Aug 13 at 18:54
yael
2,0341145
2,0341145
1
Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again? And, if such a line is encountered, would it still count as being one of the first two lines?
â Dirk Herrmann
Aug 13 at 22:41
1
regarding to Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again - YES I MEAN THAT
â yael
Aug 13 at 22:49
@yael Can you update your example (before + after) so that your point 3 is covered? It would be helpful if your example would reflect all the points that you need on what you're asking... Thanks!
â Filipe Brandenburger
Aug 15 at 5:46
add a comment |Â
1
Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again? And, if such a line is encountered, would it still count as being one of the first two lines?
â Dirk Herrmann
Aug 13 at 22:41
1
regarding to Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again - YES I MEAN THAT
â yael
Aug 13 at 22:49
@yael Can you update your example (before + after) so that your point 3 is covered? It would be helpful if your example would reflect all the points that you need on what you're asking... Thanks!
â Filipe Brandenburger
Aug 15 at 5:46
1
1
Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again? And, if such a line is encountered, would it still count as being one of the first two lines?
â Dirk Herrmann
Aug 13 at 22:41
Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again? And, if such a line is encountered, would it still count as being one of the first two lines?
â Dirk Herrmann
Aug 13 at 22:41
1
1
regarding to Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again - YES I MEAN THAT
â yael
Aug 13 at 22:49
regarding to Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again - YES I MEAN THAT
â yael
Aug 13 at 22:49
@yael Can you update your example (before + after) so that your point 3 is covered? It would be helpful if your example would reflect all the points that you need on what you're asking... Thanks!
â Filipe Brandenburger
Aug 15 at 5:46
@yael Can you update your example (before + after) so that your point 3 is covered? It would be helpful if your example would reflect all the points that you need on what you're asking... Thanks!
â Filipe Brandenburger
Aug 15 at 5:46
add a comment |Â
2 Answers
2
active
oldest
votes
up vote
2
down vote
accepted
Extending on Steve's answer:
awk '/HBASE_MASTER_OPTS/&&/ -XX:[+]UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/x++;print;next/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Update: Here's a more maintenance friendly version, where every string only occurs once.
awk 'BEGINp="-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"m=0/HBASE_MASTER_OPTS/m=1;++xm&&index($0,p)print;nextm&&x<=2gsub(/"$/," " p """)1' ams-hbase-env-template.txt
And some explanation:
- In the first version in the pattern matching,
[+]
is used for the literal + character, because otherwise+
would be interpreted as special character.
The remaining points are about the second version:
- In the
BEGIN
clause, the properties stringp
is defined. All the following clauses apply to the lines of the input. m=0
: This clause has no condition, which means it applies to every line, such that for each line firstm
(for match) will be set to zero./HBASE_MASTER_OPTS/m=1;++x
: If a line matches theHBASE_MASTER_OPTS
string,m
is set and our line counter is incremented.m&&index($0,p)print;next
: this clause checks if, in addition to a match indicated bym
, also the properties string is contained in the input line. In such a caseindex
will return an non-zero value. If so, we print the line as it is (not adding the properties again) and withnext
skip the remaining clauses and start processing the next line. Note that the following clauses were originally provided by Steve and only adapted by me:m&&x<=2gsub(/"$/," " p """)
: if we reach this point and we have a matching line and our counter has not exceeded 2, we modify$0
(the input line) by prepending the terminal"
with a blank and our properties string. Apart from that, no output is produced, which will be done by the next clause.1
: This is a condition (always true) without an action, which means the action defaults to printing the input line.
it still append the properties even if they are exist in the lines
â yael
Aug 13 at 22:56
ok I will wait for the fix
â yael
Aug 13 at 23:03
what to say , wonderful really ,
â yael
Aug 13 at 23:23
add a comment |Â
up vote
3
down vote
How about this awk
solution. Creates the desired output in the question.
awk '/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Try it online!
one problem is that when we run your CLI , let say we put the output to out.txt , on the next time awk will append the lines , so actually we get duplicate properties
â yael
Aug 13 at 22:48
so can you fix the awk syntax , so on the next awk running it will not append the properties because they are already exists
â yael
Aug 13 at 22:50
add a comment |Â
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
Extending on Steve's answer:
awk '/HBASE_MASTER_OPTS/&&/ -XX:[+]UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/x++;print;next/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Update: Here's a more maintenance friendly version, where every string only occurs once.
awk 'BEGINp="-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"m=0/HBASE_MASTER_OPTS/m=1;++xm&&index($0,p)print;nextm&&x<=2gsub(/"$/," " p """)1' ams-hbase-env-template.txt
And some explanation:
- In the first version in the pattern matching,
[+]
is used for the literal + character, because otherwise+
would be interpreted as special character.
The remaining points are about the second version:
- In the
BEGIN
clause, the properties stringp
is defined. All the following clauses apply to the lines of the input. m=0
: This clause has no condition, which means it applies to every line, such that for each line firstm
(for match) will be set to zero./HBASE_MASTER_OPTS/m=1;++x
: If a line matches theHBASE_MASTER_OPTS
string,m
is set and our line counter is incremented.m&&index($0,p)print;next
: this clause checks if, in addition to a match indicated bym
, also the properties string is contained in the input line. In such a caseindex
will return an non-zero value. If so, we print the line as it is (not adding the properties again) and withnext
skip the remaining clauses and start processing the next line. Note that the following clauses were originally provided by Steve and only adapted by me:m&&x<=2gsub(/"$/," " p """)
: if we reach this point and we have a matching line and our counter has not exceeded 2, we modify$0
(the input line) by prepending the terminal"
with a blank and our properties string. Apart from that, no output is produced, which will be done by the next clause.1
: This is a condition (always true) without an action, which means the action defaults to printing the input line.
it still append the properties even if they are exist in the lines
â yael
Aug 13 at 22:56
ok I will wait for the fix
â yael
Aug 13 at 23:03
what to say , wonderful really ,
â yael
Aug 13 at 23:23
add a comment |Â
up vote
2
down vote
accepted
Extending on Steve's answer:
awk '/HBASE_MASTER_OPTS/&&/ -XX:[+]UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/x++;print;next/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Update: Here's a more maintenance friendly version, where every string only occurs once.
awk 'BEGINp="-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"m=0/HBASE_MASTER_OPTS/m=1;++xm&&index($0,p)print;nextm&&x<=2gsub(/"$/," " p """)1' ams-hbase-env-template.txt
And some explanation:
- In the first version in the pattern matching,
[+]
is used for the literal + character, because otherwise+
would be interpreted as special character.
The remaining points are about the second version:
- In the
BEGIN
clause, the properties stringp
is defined. All the following clauses apply to the lines of the input. m=0
: This clause has no condition, which means it applies to every line, such that for each line firstm
(for match) will be set to zero./HBASE_MASTER_OPTS/m=1;++x
: If a line matches theHBASE_MASTER_OPTS
string,m
is set and our line counter is incremented.m&&index($0,p)print;next
: this clause checks if, in addition to a match indicated bym
, also the properties string is contained in the input line. In such a caseindex
will return an non-zero value. If so, we print the line as it is (not adding the properties again) and withnext
skip the remaining clauses and start processing the next line. Note that the following clauses were originally provided by Steve and only adapted by me:m&&x<=2gsub(/"$/," " p """)
: if we reach this point and we have a matching line and our counter has not exceeded 2, we modify$0
(the input line) by prepending the terminal"
with a blank and our properties string. Apart from that, no output is produced, which will be done by the next clause.1
: This is a condition (always true) without an action, which means the action defaults to printing the input line.
it still append the properties even if they are exist in the lines
â yael
Aug 13 at 22:56
ok I will wait for the fix
â yael
Aug 13 at 23:03
what to say , wonderful really ,
â yael
Aug 13 at 23:23
add a comment |Â
up vote
2
down vote
accepted
up vote
2
down vote
accepted
Extending on Steve's answer:
awk '/HBASE_MASTER_OPTS/&&/ -XX:[+]UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/x++;print;next/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Update: Here's a more maintenance friendly version, where every string only occurs once.
awk 'BEGINp="-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"m=0/HBASE_MASTER_OPTS/m=1;++xm&&index($0,p)print;nextm&&x<=2gsub(/"$/," " p """)1' ams-hbase-env-template.txt
And some explanation:
- In the first version in the pattern matching,
[+]
is used for the literal + character, because otherwise+
would be interpreted as special character.
The remaining points are about the second version:
- In the
BEGIN
clause, the properties stringp
is defined. All the following clauses apply to the lines of the input. m=0
: This clause has no condition, which means it applies to every line, such that for each line firstm
(for match) will be set to zero./HBASE_MASTER_OPTS/m=1;++x
: If a line matches theHBASE_MASTER_OPTS
string,m
is set and our line counter is incremented.m&&index($0,p)print;next
: this clause checks if, in addition to a match indicated bym
, also the properties string is contained in the input line. In such a caseindex
will return an non-zero value. If so, we print the line as it is (not adding the properties again) and withnext
skip the remaining clauses and start processing the next line. Note that the following clauses were originally provided by Steve and only adapted by me:m&&x<=2gsub(/"$/," " p """)
: if we reach this point and we have a matching line and our counter has not exceeded 2, we modify$0
(the input line) by prepending the terminal"
with a blank and our properties string. Apart from that, no output is produced, which will be done by the next clause.1
: This is a condition (always true) without an action, which means the action defaults to printing the input line.
Extending on Steve's answer:
awk '/HBASE_MASTER_OPTS/&&/ -XX:[+]UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M/x++;print;next/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Update: Here's a more maintenance friendly version, where every string only occurs once.
awk 'BEGINp="-XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"m=0/HBASE_MASTER_OPTS/m=1;++xm&&index($0,p)print;nextm&&x<=2gsub(/"$/," " p """)1' ams-hbase-env-template.txt
And some explanation:
- In the first version in the pattern matching,
[+]
is used for the literal + character, because otherwise+
would be interpreted as special character.
The remaining points are about the second version:
- In the
BEGIN
clause, the properties stringp
is defined. All the following clauses apply to the lines of the input. m=0
: This clause has no condition, which means it applies to every line, such that for each line firstm
(for match) will be set to zero./HBASE_MASTER_OPTS/m=1;++x
: If a line matches theHBASE_MASTER_OPTS
string,m
is set and our line counter is incremented.m&&index($0,p)print;next
: this clause checks if, in addition to a match indicated bym
, also the properties string is contained in the input line. In such a caseindex
will return an non-zero value. If so, we print the line as it is (not adding the properties again) and withnext
skip the remaining clauses and start processing the next line. Note that the following clauses were originally provided by Steve and only adapted by me:m&&x<=2gsub(/"$/," " p """)
: if we reach this point and we have a matching line and our counter has not exceeded 2, we modify$0
(the input line) by prepending the terminal"
with a blank and our properties string. Apart from that, no output is produced, which will be done by the next clause.1
: This is a condition (always true) without an action, which means the action defaults to printing the input line.
edited Aug 14 at 20:43
answered Aug 13 at 22:52
Dirk Herrmann
31138
31138
it still append the properties even if they are exist in the lines
â yael
Aug 13 at 22:56
ok I will wait for the fix
â yael
Aug 13 at 23:03
what to say , wonderful really ,
â yael
Aug 13 at 23:23
add a comment |Â
it still append the properties even if they are exist in the lines
â yael
Aug 13 at 22:56
ok I will wait for the fix
â yael
Aug 13 at 23:03
what to say , wonderful really ,
â yael
Aug 13 at 23:23
it still append the properties even if they are exist in the lines
â yael
Aug 13 at 22:56
it still append the properties even if they are exist in the lines
â yael
Aug 13 at 22:56
ok I will wait for the fix
â yael
Aug 13 at 23:03
ok I will wait for the fix
â yael
Aug 13 at 23:03
what to say , wonderful really ,
â yael
Aug 13 at 23:23
what to say , wonderful really ,
â yael
Aug 13 at 23:23
add a comment |Â
up vote
3
down vote
How about this awk
solution. Creates the desired output in the question.
awk '/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Try it online!
one problem is that when we run your CLI , let say we put the output to out.txt , on the next time awk will append the lines , so actually we get duplicate properties
â yael
Aug 13 at 22:48
so can you fix the awk syntax , so on the next awk running it will not append the properties because they are already exists
â yael
Aug 13 at 22:50
add a comment |Â
up vote
3
down vote
How about this awk
solution. Creates the desired output in the question.
awk '/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Try it online!
one problem is that when we run your CLI , let say we put the output to out.txt , on the next time awk will append the lines , so actually we get duplicate properties
â yael
Aug 13 at 22:48
so can you fix the awk syntax , so on the next awk running it will not append the properties because they are already exists
â yael
Aug 13 at 22:50
add a comment |Â
up vote
3
down vote
up vote
3
down vote
How about this awk
solution. Creates the desired output in the question.
awk '/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Try it online!
How about this awk
solution. Creates the desired output in the question.
awk '/HBASE_MASTER_OPTS/&&x<2gsub(/"$/," -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=2M"");x++1' ams-hbase-env-template.txt
Try it online!
answered Aug 13 at 22:24
steve
12.9k22149
12.9k22149
one problem is that when we run your CLI , let say we put the output to out.txt , on the next time awk will append the lines , so actually we get duplicate properties
â yael
Aug 13 at 22:48
so can you fix the awk syntax , so on the next awk running it will not append the properties because they are already exists
â yael
Aug 13 at 22:50
add a comment |Â
one problem is that when we run your CLI , let say we put the output to out.txt , on the next time awk will append the lines , so actually we get duplicate properties
â yael
Aug 13 at 22:48
so can you fix the awk syntax , so on the next awk running it will not append the properties because they are already exists
â yael
Aug 13 at 22:50
one problem is that when we run your CLI , let say we put the output to out.txt , on the next time awk will append the lines , so actually we get duplicate properties
â yael
Aug 13 at 22:48
one problem is that when we run your CLI , let say we put the output to out.txt , on the next time awk will append the lines , so actually we get duplicate properties
â yael
Aug 13 at 22:48
so can you fix the awk syntax , so on the next awk running it will not append the properties because they are already exists
â yael
Aug 13 at 22:50
so can you fix the awk syntax , so on the next awk running it will not append the properties because they are already exists
â yael
Aug 13 at 22:50
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%2f462371%2fhow-to-add-properties-in-the-end-of-the-two-first-lines-with-double-quote%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
Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again? And, if such a line is encountered, would it still count as being one of the first two lines?
â Dirk Herrmann
Aug 13 at 22:41
1
regarding to Your point 3 is not fully clear to me: Do you mean that if a line contains HBASE_MASTER_OPTS, but also already contains the properties, you do not want to add them again - YES I MEAN THAT
â yael
Aug 13 at 22:49
@yael Can you update your example (before + after) so that your point 3 is covered? It would be helpful if your example would reflect all the points that you need on what you're asking... Thanks!
â Filipe Brandenburger
Aug 15 at 5:46