如何使用sed提取子字符串

我有一个包含以下行的文件:

  <parameter name="PortMappingEnabled" access="readWrite" type="xsd:boolean"></parameter>

<parameter name="PortMappingLeaseDuration" access="readWrite" activeNotify="canDeny" type="xsd:unsignedInt"></parameter>

<parameter name="RemoteHost" access="readWrite"></parameter>

<parameter name="ExternalPort" access="readWrite" type="xsd:unsignedInt"></parameter>

<parameter name="ExternalPortEndRange" access="readWrite" type="xsd:unsignedInt"></parameter>

<parameter name="InternalPort" access="readWrite" type="xsd:unsignedInt"></parameter>

<parameter name="PortMappingProtocol" access="readWrite"></parameter>

<parameter name="InternalClient" access="readWrite"></parameter>

<parameter name="PortMappingDescription" access="readWrite"></parameter>

我想在此文件上执行命令以仅提取参数名称,如以下输出所示:

$sedcommand file.txt

PortMappingEnabled

PortMappingLeaseDuration

RemoteHost

ExternalPort

ExternalPortEndRange

InternalPort

PortMappingProtocol

InternalClient

PortMappingDescription

这个命令可能是什么?

回答:

你要awk

这将是一个快速而肮脏的hack:

awk -F "\"" '{print $2}' /tmp/file.txt

PortMappingEnabled

PortMappingLeaseDuration

RemoteHost

ExternalPort

ExternalPortEndRange

InternalPort

PortMappingProtocol

InternalClient

PortMappingDescription

以上是 如何使用sed提取子字符串 的全部内容, 来源链接: utcz.com/qa/422189.html

回到顶部