"test" /> "ele::1234-6ren">
gpt4 book ai didi

linux - 如何删除特定模式后的行并提取某些内容

转载 作者:太空宇宙 更新时间:2023-11-04 04:37:04 25 4
gpt4 key购买 nike

更新这是我的文件:

<department name="/fighters" id="123879" group="channel" case="none" use="no">
<options index_name="index.html" listing="0" sum="no" allowed="no" />
<target prefix="ttp" suffix=".net" />
<type="effort">
<region="20491" readonly="fs1a" readwrite="fs1a" upload="yes" download="yes" repl="yes" hard="0" soft"0" prio="0" write="no" stage="yes" migrate="no" size="0" >
<read="content" readwrite="content" hard="215822106624" soft="237296943104" prio="5" write="yes" stage="yes" migrate="no" size="0" />
<overflow name="20491-set-writable" />
</replicate>
<region="20576" readonly="fs1a" readwrite="fs1a" upload="yes" download="yes" repl="yes" hard="0" soft"0" prio="0" write="no" stage="yes" migrate="no" size="0" >
<read="content" readwrite="content" hard="215822106624" soft="237296943104" prio="5" write="yes" stage="yes" migrate="no" size="0" />
<overflow name="20576-set-writable" />
</replicate>
</replication>
<user="T:106603" />
<user="T:123879" />
<user="test" />
<user="ele::123456" />
<user="company-temp" />
<user="companymw2" />
<user="bird" />
<user="coding11" />
<user="plazamedia" />
<allow go="123456=abcdefghijklmnopqrstuvwxyz" />
</department>

我写了一个像这样的bash:

awk < test.xml -Fuser= '{ print $2 }' | sed '/^$/d' |  cut -d" " -f1

结果类似于:

"T:106603"
"T:123879"
"test"
"ele::123456"
"company-temp"
"companymw2"
"bird"
"coding11"
"plazamedia"

但想象一下结果是:

"T:106603" />
"T:123879" />
"test" />
"ele::123456" />
"company-temp" />
"companymw2" />
"bird" />
"coding11" />
"plazamedia" />

首先,我怎么能说删除第二个之后的所有内容?

其次,我怎么说提取 "" 之间的所有内容?

我喜欢使用 sedawk

提前谢谢

最佳答案

试试这个:

awk -F'"' '/<user=/{ print $2 }' file

关于linux - 如何删除特定模式后的行并提取某些内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21821287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com