sed/awk 删除字符串

sed/awk 删除字符串

我有一个txt文件,其中包含以下信息

-Xmx4096m -Xms4096m -verbose:gc -XX:+UseParNewGC -XX:+CMSParallelRemarkEnabled -XX:+ScavengeBeforeFullGC -Dsun.net.inetaddr.ttl=3600 -XX:NewSize=1024m -XX:MaxNewSize=1024m -XX:CMSInitiatingOccupancyFraction=70 -XX:+UseCMSInitiatingOccupancyOnly -XX:+PrintTenuringDistribution -XX:SurvivorRatio=6 -XX:+UseConcMarkSweepGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC -XX:PermSize=256m -XX:MaxPermSize=256m -Xloggc:/www/logs/jboss/macys-navapp_master_mcomnavapp_m01/gc-log.txt -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/www/logs/heapdump/macys-navapp_master_mcomnavapp_m01/macys-navapp_master_mcomnavapp_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 -Dfile.encoding=ISO-8859-1 -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 -Dsdp.configuration.home=/www/apps/properties -Dzookeeper.sasl.client=false -agentpath:/www/apps/dynatrace/dynatrace_apm/agent/lib64/libdtagent.so=name=agent_name,collector=dtcoldev_new:9998 XX:MaxPermSize=256m -Xloggc:/www/logs/jboss/macys-navapp_master_mcomnavapp_m01/gc-log.txt -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/www/logs/heapdump/macys-navapp_master_mcomnavapp_m01/macys-navapp_master_mcomnavapp_m01.hprof -Djava.net.preferIPv4Stack=true -Dorg.jboss.resolver.warning=true

我只想删除字符串内容-agentpath:/www/apps/dynatrace/dynatrace_apm/agent/lib64/libdtagent.so=name=agent_name,collector=dtcoldev_new:9998,之后什么都不删除

目前我正在使用

sed 's/-agentpath.*//' -i files

这将删除agentpath.如何限制删除上面的字符串?

答案1

限制*为非空格:

sed -i 's/-agentpath[^ ]*//' files

相关内容