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
[:digit:]
, so[[:digit:]]*
would match a string of digits...*
:sed -i -e 's/-Djava.util.logging.FileHandler.limit\S*\s//g' sample.txt