[英]Intersection between two shell lists without temp files
關於我想要的結果,網上有很多問題。 想象一下,您在shell腳本中有兩個列表:
LIST_ONE="key1 key2 key3 key4"
LIST_TWO="key2 key3 key5"
我想要這兩個列表的交集:
LIST_FIN="key2 key3"
我發現有一些事情要做,例如使用comm
命令。 但是它總是使用文件,而我不能使用臨時文件。
謝謝你的建議。
使用流程替代:
grep -o -f <(echo "$LIST_TWO" | tr ' ' '\n') <<< "$LIST_ONE" | xargs
key2 key3
這樣的事情怎么樣:
$ LIST_ONE="key1 key2 key3 key4"
$ LIST_TWO="key2 key3 key5"
$ comm -12 <(tr ' ' '\n' <<< "${LIST_ONE}" | sort) <(tr ' ' '\n' <<< "${LIST_TWO}" | sort)
key2
key3
$
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.