Roflmao711
Roflmao711

Reputation: 5

How to grep for the whole string after a word in the string is matched

I have this

-Xmx10240m -Xms10240m -verbose:gc -XX:+CMSParallelRemarkEnabled -XX:+UseParNewGC -XX:+ScavengeBeforeFullGC -Dsun.net.inetaddr.ttl=3600 -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+PrintTenuringDistribution -XX:SurvivorRatio=6 -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -XX:PermSize=512m -XX:MaxPermSize=512m -Xloggc:/www/logs/jboss/macys-navapp_master_prod_cellA_m01/gc-log.txt -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/www/logs/heapdump/navapp_master_prod_cellA__m01/navapp_master_prod_cellA_m01.hprof -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true -XX:+UseCompressedOops -Dclient.encoding.override=ISO-8859-1 -XX:+DisableExplicitGC -Dorg.apache.jasper.Constants.USE_INSTANCE_MANAGER_FOR_TAGS=false -Dorg.apache.jasper.Constants.USE_INSTANCE_MANAGER -Dorg.apache.jasper.runtime.JspFactoryImpl.USE_POOL=false -Dorg.apache.jasper.runtime.BodyContentImpl.LIMIT_BUFFER=true -XX:NewSize=3072m -XX:MaxNewSize=3072m -agentpath:/www/a/apps/dynatrace/dt.so=name=server1_ProdCellA_master_m1,server=ct_collector:9998 -Dfile.encoding=ISO-8859-1 -Dsdp.configuration.home=/www/apps/properties -XX:+UseLargePages -Dzookeeper.sasl.client=false

I want to be able to grep this whole string after i matched "-agentpath" "-agentpath:/www/a/apps/dynatrace/dt.so=name=server1_ProdCellA_master_m1,server=ct_collector:9998"

This is the current command i'm working with but it's not working "cat cached_java_opts | awk '/-agentpath/ {print $(NF)}'"

Thanks you

Upvotes: 0

Views: 152

Answers (2)

P....
P....

Reputation: 18351

awk solution:

awk -F'-agentpath:' '{split($2,a," ") ;print FS a[1]}' infile
-agentpath:/www/a/apps/dynatrace/dt.so=name=server1_ProdCellA_master_m1,server=ct_collector:9998

grep : more or less,same as already answered.

grep -oP '\-agentpath:.*?\s' infile
-agentpath:/www/a/apps/dynatrace/dt.so=name=server1_ProdCellA_master_m1,server=ct_collector:9998

Upvotes: 1

Jean-François Fabre
Jean-François Fabre

Reputation: 140148

launch grep like this:

grep -o '\-agentpath[^ ]*' yourfile

The -o option prints only the matching pattern (not the matching line). Since the pattern is configured to expand until the first space, you'll get the entire argument (this works because it is not the last argument of the command line). Maybe it could be improved with grep -oE '\-agentpath([^ ]*|.*$)'

Upvotes: 1

Related Questions