-1

Below is a sample file content:

cat sample.txt

-server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -Djava.util.logging.FileHandler.limit=12908998 -XX:ParallelGCThreads=4 -Xms1536m -Xmx1536m -Xmn512m -Xss4m -XX:LargePageSizeInBytes=4m -XX:-BindGCTaskThreadsToCPUs -XX:PermSize=256m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=3 -XX:SurvivorRatio=20 -Dweblogic.SocketReaders=10 

In a seperate mapping file, I'm given a list of strings one of which is -Djava.util.logging.FileHandler.limit. if this string is found then it should be removed along with its value.

Thus, I wish to remove the entire entry ( along with its value ) -Djava.util.logging.FileHandler.limit=12908998

I'm able to remove -Djava.util.logging.FileHandler.limit by replacing -Djava.util.logging.FileHandler.limit to null as below:

sed -e s/-Djava.util.logging.FileHandler.limit//g -i sample.txt

As regex \S*\s get me the entire string separated by whitespace I tried but failed with the below attempt:

sed -e s/-Djava.util.logging.FileHandler.limit\S*\s//g -i sample.txt

But I'm not sure how do I remove along with its value i.e. -Djava.util.logging.FileHandler.limit=12908998

Desired output:

cat sample.txt

-server -XX:+UseParallelGC -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+AggressiveHeap -XX:+PrintHeapAtGC -XX:ParallelGCThreads=4 -Xms1536m -Xmx1536m -Xmn512m -Xss4m -XX:LargePageSizeInBytes=4m -XX:-BindGCTaskThreadsToCPUs -XX:PermSize=256m -XX:MaxPermSize=512m -XX:MaxTenuringThreshold=3 -XX:SurvivorRatio=20 -Dweblogic.SocketReaders=10 
2
  • 1
    There's a regex for numbers too: [:digit:], so [[:digit:]]* would match a string of digits...CommentedMar 27, 2022 at 23:05
  • 1
    I think the code you tried would have worked if you only put the the pattern in quotation marks; otherwise, your shell may be globbing on the *: sed -i -e 's/-Djava.util.logging.FileHandler.limit\S*\s//g' sample.txt
    – frabjous
    CommentedMar 27, 2022 at 23:49

1 Answer 1

1

Your sed command is working fine, you are just missing the quotes.

sed -e 's/-Djava.util.logging.FileHandler.limit=\S*\s//g' 
3
  • The solution provided should work for both numeric and alpha-numerics. Kindly suggest.
    – Ashar
    CommentedMar 28, 2022 at 3:55
  • the solution does not work if -Djava.util.logging.FileHandler.limit=/log/tmp/maxlimit
    – Ashar
    CommentedMar 28, 2022 at 3:56
  • @Ashar noted. You should have that included in your initial question.CommentedMar 28, 2022 at 4:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.