我必须根据其他值(包名称)从大型XML文件中提取值(即值),首先删除重复项,然后对其进行循环。
grep -i 'abc.jar' /tmp/<filename>
==> 还删除重复项
output =>
<Package Name="abc.jar="OUI" Version="1.o">
<Property Name="InstallLocation" Value="/<some path>/abc.jar"/>
<Package Name="abc.jar" Evidence="OUI" Version="1.0">
<Property Name="InstallLocation" Value="/<some path/abc.jar"/>
<Package Name="abc.jar" Evidence="OUI" Version="1.0">
<Property Name="InstallLocation" Value="/<some path>/abc.jar"/>
我可以使用以下命令提取所有软件包名称,但无法继续进行操作。
grep -P -o -e '(?<=Package Name=").*?(?=")' <filename>
abc.jar
abc.jar
xyz.ear
xyz.ear
....contd
答案 0 :(得分:0)
您可以通过管道传输到sort -u
:
grep -P -o -e '(?<=Package Name=").*?(?=")' <filename> | sort -u
-u
选项:
-u, --unique
Unique keys. Suppress all lines that have a key that is equal to an already processed one.
This option, similarly to -s, implies a stable sort. If used with -c or -C,
sort also checks that there are no lines with duplicate keys.