簡體   English   中英

Bash-如何刪除相似(不相同)的行? Grep? 塞德 啊

[英]Bash - How to remove similar (not identical) lines? Grep? Sed? Awk?

我需要從文件中刪除相似(不相同)的行。 例如

file.txt

/Bota-Espaco-Fashion-Com-Tachas-e-Cristais-Bege-1472878.html#botas
/Bota-Raphaella-Booz-Cano-Curto-2-Fivelas-Vermelha-1458535.html#botas
/Bota-Dumond-Country-3-Fivelas-Caramelo-1481004.html#botas
/Bota-Espaco-Fashion-Com-Tachas-e-Cristais-Bege-1472878.html
/Bota-Raphaella-Booz-Cano-Curto-2-Fivelas-Vermelha-1458535.html
/Bota-Dumond-Country-3-Fivelas-Caramelo-1481004.html

所需結果:(以#botas結尾的唯一行)

/Bota-Espaco-Fashion-Com-Tachas-e-Cristais-Bege-1472878.html#botas
/Bota-Raphaella-Booz-Cano-Curto-2-Fivelas-Vermelha-1458535.html#botas
/Bota-Dumond-Country-3-Fivelas-Caramelo-1481004.html#botas

有什么方便的解決方案嗎?

使用awk:

awk -F\# '!a[$1]++' your_file.txt

輸出:

/Bota-Espaco-Fashion-Com-Tachas-e-Cristais-Bege-1472878.html#botas
/Bota-Raphaella-Booz-Cano-Curto-2-Fivelas-Vermelha-1458535.html#botas
/Bota-Dumond-Country-3-Fivelas-Caramelo-1481004.html#botas

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM