[英]remove lines in file from stream
cat file_a
aaa
bbb
ccc
cat file_b
ddd
eee
fff
cat file_x
bbb
ccc
ddd
eee
我要cat file_a file_b | remove_from_stream_what_is_in(file_x)
cat file_a file_b | remove_from_stream_what_is_in(file_x)
結果:
aaa
fff
如果沒有基本的過濾器可以做到這一點,那么我想知道是否有辦法使用ruby -ne '...'
。
嘗試:
$ cat file_a file_b | grep -vFf file_x
aaa
fff
-v
表示刪除匹配的行。
-F
告訴grep將匹配模式視為固定字符串,而不是正則表達式。
-f file_x
告訴grep從file_x
行獲取匹配模式。
您可能要考慮的其他選項是:
-w
告訴grep僅匹配完整的單詞。
-x
告訴grep只匹配完整的行。
IO.write('file_a', %w| aaa bbb ccc |.join("\n")) #=> 11
IO.write('file_b', %w| ddd eee fff |.join("\n")) #=> 11
IO.write('file_x', %w| bbb ccc ddd eee |.join("\n")) #=> 15
從Ruby:
IO.readlines('file_a', chomp: true) + IO.readlines('file_b', chomp: true) -
IO.readlines('file_x', chomp: true)
#=> ["aaa", "fff"]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.