Skip to main content
added 12 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

The command requires GNU sed and seems to insert the string Dcom.sun.management.jmxremote.ssl=false followed by a newline before the first occurance of -jar at the end of a line.

Example:

something
something
something-jar
something

is transformed into

something
something
somethingDcom.sun.management.jmxremote.ssl=false
-jar
something

The sed command reads the whole file into memory by running H for each line of the file (appends the current line into the "hold space" with a newline character at the start). When it reaches the last line ($), it swaps the hold space with the pattern space (x) and deletes the first newline (put there by running H for the first line of the file). It then substitutes -jar\n with Dcom.sun.management.jmxremote.ssl=false\n-jar\n (the & is whatever was matched by the expression). It then prints the collected lines (p).

Another way of doing the same thing with awk:

awk 'skip==0 && sub("-jar$", "Dcom.sun.management.jmxremote.ssl=false\n-jar") { skip=1 } { print }' "$File"

This tries to do the same substitution on each line, and when it succeeds it sets skip=1 which will cause it to not try again. Every line is then printed regardless of whether a substitution occurred or not.

This does not store the whole file in memory.

The command requires GNU sed and seems to insert the string Dcom.sun.management.jmxremote.ssl=false followed by a newline before the first occurance of -jar at the end of a line.

Example:

something
something
something-jar
something

is transformed into

something
something
somethingDcom.sun.management.jmxremote.ssl=false
-jar
something

The sed command reads the whole file into memory by running H for each line of the file (appends the current line into the "hold space" with a newline character at the start). When it reaches the last line, it swaps the hold space with the pattern space and deletes the first newline (put there by running H for the first line of the file). It then substitutes -jar\n with Dcom.sun.management.jmxremote.ssl=false\n-jar\n (the & is whatever was matched by the expression).

Another way of doing the same thing with awk:

awk 'skip==0 && sub("-jar$", "Dcom.sun.management.jmxremote.ssl=false\n-jar") { skip=1 } { print }'

This tries to do the same substitution on each line, and when it succeeds it sets skip=1 which will cause it to not try again. Every line is then printed.

The command requires GNU sed and seems to insert the string Dcom.sun.management.jmxremote.ssl=false followed by a newline before the first occurance of -jar at the end of a line.

Example:

something
something
something-jar
something

is transformed into

something
something
somethingDcom.sun.management.jmxremote.ssl=false
-jar
something

The sed command reads the whole file into memory by running H for each line of the file (appends the current line into the "hold space" with a newline character at the start). When it reaches the last line ($), it swaps the hold space with the pattern space (x) and deletes the first newline (put there by running H for the first line of the file). It then substitutes -jar\n with Dcom.sun.management.jmxremote.ssl=false\n-jar\n (the & is whatever was matched by the expression). It then prints the collected lines (p).

Another way of doing the same thing with awk:

awk 'skip==0 && sub("-jar$", "Dcom.sun.management.jmxremote.ssl=false\n-jar") { skip=1 } { print }' "$File"

This tries to do the same substitution on each line, and when it succeeds it sets skip=1 which will cause it to not try again. Every line is printed regardless of whether a substitution occurred or not.

This does not store the whole file in memory.

added 316 characters in body
Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

The command requires GNU sed and seems to insert the string Dcom.sun.management.jmxremote.ssl=false followed by a newline before the first occurance of -jar at the end of a line.

Example:

something
something
something-jar
something

is transformed into

something
something
somethingDcom.sun.management.jmxremote.ssl=false
-jar
something

The sed command reads the whole file into memory by running H for each line of the file (appends the current line into the "hold space" with a newline character at the start). When it reaches the last line, it swaps the hold space with the pattern space and deletes the first newline (put there by running H for the first line of the file). It then substitutes -jar\n with Dcom.sun.management.jmxremote.ssl=false\n-jar\n (the & is whatever was matched by the expression).

Another way of doing the same thing with awk:

awk 'skip==0 && sub("-jar$", "Dcom.sun.management.jmxremote.ssl=false\n-jar") { skip=1 } { print }'

This tries to do the same substitution on each line, and when it succeeds it sets skip=1 which will cause it to not try again. Every line is then printed.

The command requires GNU sed and seems to insert the string Dcom.sun.management.jmxremote.ssl=false followed by a newline before the first occurance of -jar at the end of a line.

Example:

something
something
something-jar
something

is transformed into

something
something
somethingDcom.sun.management.jmxremote.ssl=false
-jar
something

The sed command reads the whole file into memory by running H for each line of the file (appends the current line into the "hold space" with a newline character at the start). When it reaches the last line, it swaps the hold space with the pattern space and deletes the first newline (put there by running H for the first line of the file). It then substitutes -jar\n with Dcom.sun.management.jmxremote.ssl=false\n-jar\n (the & is whatever was matched by the expression).

The command requires GNU sed and seems to insert the string Dcom.sun.management.jmxremote.ssl=false followed by a newline before the first occurance of -jar at the end of a line.

Example:

something
something
something-jar
something

is transformed into

something
something
somethingDcom.sun.management.jmxremote.ssl=false
-jar
something

The sed command reads the whole file into memory by running H for each line of the file (appends the current line into the "hold space" with a newline character at the start). When it reaches the last line, it swaps the hold space with the pattern space and deletes the first newline (put there by running H for the first line of the file). It then substitutes -jar\n with Dcom.sun.management.jmxremote.ssl=false\n-jar\n (the & is whatever was matched by the expression).

Another way of doing the same thing with awk:

awk 'skip==0 && sub("-jar$", "Dcom.sun.management.jmxremote.ssl=false\n-jar") { skip=1 } { print }'

This tries to do the same substitution on each line, and when it succeeds it sets skip=1 which will cause it to not try again. Every line is then printed.

Source Link
Kusalananda
  • 355.9k
  • 42
  • 735
  • 1.1k

The command requires GNU sed and seems to insert the string Dcom.sun.management.jmxremote.ssl=false followed by a newline before the first occurance of -jar at the end of a line.

Example:

something
something
something-jar
something

is transformed into

something
something
somethingDcom.sun.management.jmxremote.ssl=false
-jar
something

The sed command reads the whole file into memory by running H for each line of the file (appends the current line into the "hold space" with a newline character at the start). When it reaches the last line, it swaps the hold space with the pattern space and deletes the first newline (put there by running H for the first line of the file). It then substitutes -jar\n with Dcom.sun.management.jmxremote.ssl=false\n-jar\n (the & is whatever was matched by the expression).