简体   繁体   English

使用“ uniq” bash跳过前n个字符来打印唯一输出

[英]Print Unique output using “uniq” bash skipping first n characters

So I am trying to print a unique output using the "uinq" utility in bash but it doesn't seem to work for me. 因此,我尝试使用bash中的“ uinq”实用程序来打印唯一的输出,但它似乎对我不起作用。

Here is my file which has the following content in it:- 这是我的文件,其中包含以下内容:

Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd89f794bc0 [0x7fff9e7e6980]> { URL = "lspcidrv.kext/ -- file:///Library/Extensions/", ID = "com.evosx86.driver.lspcidrv" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a1646250 [0x7fff9e7e6980]> { URL = "ACPIPoller.kext/ -- file:///Library/Extensions/", ID = "com.rehabman.driver.ACPIPoller" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a1639640 [0x7fff9e7e6980]> { URL = "ACPIBatteryManager.kext/ -- file:///Library/Extensions/", ID = "org.rehabman.driver.AppleSmartBatteryManager" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd89f68ec60 [0x7fff9e7e6980]> { URL = "USBInjectAll.kext/ -- file:///System/Library/Extensions/", ID = "com.rehabman.driver.USBInjectAll" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a1624500 [0x7fff9e7e6980]> { URL = "RealtekRTL8111.kext/ -- file:///System/Library/Extensions/", ID = "com.insanelymac.RealtekRTL8111" }
Kext with invalid signatured (-67054) allowed: <OSKext 0x7fd8a14f00c0 [0x7fff9e7e6980]> { URL = "X86PlatformPlugin.kext/ -- file:///System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/", ID = "com.apple.driver.X86PlatformPlugin" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a15b45f0 [0x7fff9e7e6980]> { URL = "FakeSMC_LPCSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.LPCSensors" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a15a5f10 [0x7fff9e7e6980]> { URL = "FakeSMC.kext/ -- file:///System/Library/Extensions/", ID = "org.netkas.driver.FakeSMC" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a15b2030 [0x7fff9e7e6980]> { URL = "FakeSMC_CPUSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.CPUSensors" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a15ab6d0 [0x7fff9e7e6980]> { URL = "FakeSMC_ACPISensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.ACPISensors" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a159bfb0 [0x7fff9e7e6980]> { URL = "FakePCIID.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.driver.FakePCIID" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a159f440 [0x7fff9e7e6980]> { URL = "FakePCIID_Intel_HDMI_Audio.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.injector.FakePCIID-Intel-HDMI-Audio" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a159e910 [0x7fff9e7e6980]> { URL = "FakePCIID_Intel_HD_Graphics.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.injector.FakePCIID-Intel-HD-Graphics" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a15480e0 [0x7fff9e7e6980]> { URL = "CodecCommander.kext/ -- file:///System/Library/Extensions/", ID = "org.tw.CodecCommander" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fd8a153eee0 [0x7fff9e7e6980]> { URL = "AsusNBFnKeys.kext/ -- file:///System/Library/Extensions/", ID = "org.emlydinesh.driver.AsusNBFnKeys" }
KernelCache ID: A297C9A0448F4369BE17FFCFB1682182
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc8528c4d0 [0x7fff9e7e6980]> { URL = "AsusNBFnKeys.kext/ -- file:///System/Library/Extensions/", ID = "org.emlydinesh.driver.AsusNBFnKeys" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc8528cc30 [0x7fff9e7e6980]> { URL = "CodecCommander.kext/ -- file:///System/Library/Extensions/", ID = "org.tw.CodecCommander" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc852b3b10 [0x7fff9e7e6980]> { URL = "FakePCIID.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.driver.FakePCIID" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc852b24f0 [0x7fff9e7e6980]> { URL = "FakePCIID_Intel_HD_Graphics.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.injector.FakePCIID-Intel-HD-Graphics" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc852b4a40 [0x7fff9e7e6980]> { URL = "FakePCIID_Intel_HDMI_Audio.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.injector.FakePCIID-Intel-HDMI-Audio" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc852bb520 [0x7fff9e7e6980]> { URL = "FakeSMC.kext/ -- file:///System/Library/Extensions/", ID = "org.netkas.driver.FakeSMC" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc852c0ce0 [0x7fff9e7e6980]> { URL = "FakeSMC_ACPISensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.ACPISensors" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc852c7640 [0x7fff9e7e6980]> { URL = "FakeSMC_CPUSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.CPUSensors" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc852c74e0 [0x7fff9e7e6980]> { URL = "FakeSMC_GPUSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.GPUSensors" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc853f4af0 [0x7fff9e7e6980]> { URL = "FakeSMC_LPCSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.LPCSensors" }
Kext with invalid signatured (-67054) allowed: <OSKext 0x7fdc8516ea40 [0x7fff9e7e6980]> { URL = "X86PlatformPlugin.kext/ -- file:///System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/", ID = "com.apple.driver.X86PlatformPlugin" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc857cb360 [0x7fff9e7e6980]> { URL = "RealtekRTL8111.kext/ -- file:///System/Library/Extensions/", ID = "com.insanelymac.RealtekRTL8111" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc85432aa0 [0x7fff9e7e6980]> { URL = "USBInjectAll.kext/ -- file:///System/Library/Extensions/", ID = "com.rehabman.driver.USBInjectAll" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc82d049c0 [0x7fff9e7e6980]> { URL = "ACPIBatteryManager.kext/ -- file:///Library/Extensions/", ID = "org.rehabman.driver.AppleSmartBatteryManager" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc851c2520 [0x7fff9e7e6980]> { URL = "ACPIPoller.kext/ -- file:///Library/Extensions/", ID = "com.rehabman.driver.ACPIPoller" }
Kext with invalid signatured (-67062) allowed: <OSKext 0x7fdc851f3f90 [0x7fff9e7e6980]> { URL = "lspcidrv.kext/ -- file:///Library/Extensions/", ID = "com.evosx86.driver.lspcidrv" }

As you might have noticed except for the 8th field, every "kext" has one redundant entry. 您可能已经注意到,除了第8个字段外,每个“ kext”都有一个冗余条目。 I have tried using cat myfile | uniq -f8 我尝试使用cat myfile | uniq -f8 cat myfile | uniq -f8 but that doesn't work. cat myfile | uniq -f8但这不起作用。

Any help will be appreciated. 任何帮助将不胜感激。

Regards 问候

uniq requires its input to be sorted. uniq要求对其输入进行排序。 Fulfilling that, as in the following: 实现该目标,如下所示:

sed -E -e 's/OSKext 0x[^[:space:]]+ /OSKext ELIDED /g' | sort | uniq

...yields, with your input on stdin: ...产量,您在stdin上的输入是:

KernelCache ID: A297C9A0448F4369BE17FFCFB1682182
Kext with invalid signatured (-67054) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "X86PlatformPlugin.kext/ -- file:///System/Library/Extensions/IOPlatformPluginFamily.kext/Contents/PlugIns/", ID = "com.apple.driver.X86PlatformPlugin" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "ACPIBatteryManager.kext/ -- file:///Library/Extensions/", ID = "org.rehabman.driver.AppleSmartBatteryManager" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "ACPIPoller.kext/ -- file:///Library/Extensions/", ID = "com.rehabman.driver.ACPIPoller" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "AsusNBFnKeys.kext/ -- file:///System/Library/Extensions/", ID = "org.emlydinesh.driver.AsusNBFnKeys" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "CodecCommander.kext/ -- file:///System/Library/Extensions/", ID = "org.tw.CodecCommander" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakePCIID.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.driver.FakePCIID" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakePCIID_Intel_HDMI_Audio.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.injector.FakePCIID-Intel-HDMI-Audio" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakePCIID_Intel_HD_Graphics.kext/ -- file:///System/Library/Extensions/", ID = "org.rehabman.injector.FakePCIID-Intel-HD-Graphics" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakeSMC.kext/ -- file:///System/Library/Extensions/", ID = "org.netkas.driver.FakeSMC" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakeSMC_ACPISensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.ACPISensors" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakeSMC_CPUSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.CPUSensors" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakeSMC_GPUSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.GPUSensors" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "FakeSMC_LPCSensors.kext/ -- file:///System/Library/Extensions/", ID = "org.hwsensors.driver.LPCSensors" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "RealtekRTL8111.kext/ -- file:///System/Library/Extensions/", ID = "com.insanelymac.RealtekRTL8111" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "USBInjectAll.kext/ -- file:///System/Library/Extensions/", ID = "com.rehabman.driver.USBInjectAll" }
Kext with invalid signatured (-67062) allowed: <OSKext ELIDED [0x7fff9e7e6980]> { URL = "lspcidrv.kext/ -- file:///Library/Extensions/", ID = "com.evosx86.driver.lspcidrv" }

awk to the rescue! awk解救!

without resorting to sorting (pun intended) 不求助于排序(双关语意)

$ awk '{k=$8; $8=""} !a[$0]++{$8=k; print}' file | wc -l

17

print the unique entries modulus 8th field, in the same order of the input file. 以与输入文件相同的顺序打印唯一条目模数第8个字段。

if you don't want to preserve the field, it's simpler... 如果您不想保留该字段,这会更简单...

$ awk '{$8="REMOVED"} !a[$0]++' file

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM