根據我的2列表,可以使用哪些unix命令/實用程序創建最終名稱列表?這就像是在做一個SET
的操作。但是,主要的比較必須是針對NameList1
。如果NameList2
有一個額外的名稱,請不要將它包含在主列表中。unix命令執行與設置操作相當的列表比較
注:我不能讓它排序(按字母順序排列等)。我需要保留列位置(自然順序),正如我在列表頂部提供的那樣。謝謝你的幫助。
NameList1:
Joe
John
Mary
Mike
Allan
David
Andrew
Matt
NameList2:
Joe
John
Mary
George
Jeff
Allan
David
Andrew
Frank
如果我做一個diff
一個並排側比較就可以看到比較。像這樣:
-bash-4.1$ diff --side-by-side NameList1.txt NameList2.txt
Joe Joe
John John
Mary Mary
Mike | George
> Jeff
Allan Allan
David David
Andrew Andrew
Matt | Frank
結果,預期爲我的最終名單將是:
Joe
John
Mary
Mike
Allan
David
Andrew
Matt
凡George, Jeff, Frank
從NameList1刪除。我怎樣才能產生這個最終名單?有更好的工具命令嗎?我正確使用diff
嗎?
是與您的list1相同的結果嗎? – haifzhan
您的問題沒有很好地定義。 –
正如我的'主'列表中列出的是我需要生產的。所以換句話說,無論NameList2中哪些不在NameList1中,都將其從NameList1中移除。 – noober