0

We have the following line in file

more file


USA_FORMAT="-XX:LOP83746=5M -XX:+YU3635-2837"

and we want to append the following strings (line) also at the end of USA_FORMAT variable

/usr/jdk64/jdk1.8.0_112/man/man1/jarsigner.1 /usr/hdp/2.6.4.0-91/spark2/examples/jars 6 3 END

How to append the line "usr/jdk64/jdk1.8.0_112/man/man1/jarsigner.1 /usr/hdp/2.6.4.0-91/spark2/examples/jars 6 3 END" in the variable by sed or Perl one line / other approach?

NOTE - content of variable before appending can be different.

Expected output:

USA_FORMAT="-XX:LOP83746=5M -XX:+YU3635-2837 usr/jdk64/jdk1.8.0_112/man/man1/jarsigner.1 /usr/hdp/2.6.4.0-91/spark2/examples/jars 6 3 END"
1
sed -e '/^USA_FORMAT=/s,"$, /usr/.../jarsigner.1 /usr/.../jars 6 3 END",'

i.e. on the line that starts with USA_FORMAT=, replace the final " with /usr/...END" (with the final quote at the end of the new string). If it's a shell script, you could actually ignore the existing quote and instead add the new part with a new set of quotes. You'd get var="foo""bar", but that's completely valid.

Or similarly in Perl:

perl -pe 's,"$, /usr/.../jarsigner.1 /usr/.../jars 6 3 END", if /^USA_FORMAT=/'

or

export repl='/usr/ ... END'
perl -pe 's/"$/ $ENV{repl}"/ if /^USA_FORMAT=/'

so you don't need to choose the separator for s based on what the replacement string (doesn't) contain(s).

0

let the data in 'd', on bash shell terminal do;

append='/usr/jdk64/jdk1.8.0_112/man/man1/jarsigner.1 /usr/hdp/2.6.4.0-91/spark2/examples/jars 6 3 END'
sed -E "/USA_FORMAT=.+/ s~~&$append~" d

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.