gpt4 book ai didi

shell - (shell) 如何从一个文件中删除可以在另一个文件中找到的字符串?

转载 作者:行者123 更新时间:2023-12-04 19:57:07 29 4
gpt4 key购买 nike

file1.txt

aaaa
bbbb
cccc
dddd
eeee

file2.txt

DDDD
cccc
aaaa

结果

bbbb
eeee

如果能不区分大小写就更好了!

谢谢!

最佳答案

grep 可以匹配从文件中读取的模式,并打印出所有不匹配该模式的行。也可以不区分大小写地匹配,比如

grep -vi -f file2.txt file1.txt

手册页摘录:

SYNOPSIS
grep [OPTIONS] PATTERN [FILE...]
grep [OPTIONS] [-e PATTERN | -f FILE] [FILE...]

-f FILE, --file=FILE
Obtain patterns from FILE, one per line. The empty file contains zero
patterns, and therefore matches nothing. (-f is specified by POSIX.)ns zero
patterns, and therefore matches nothing. (-f is specified by POSIX.)
-i, --ignore-case
Ignore case distinctions in both the PATTERN and the input files. (-i is
specified by POSIX.)ions in both the PATTERN and the input files. (-i is
specified by POSIX.)
-v, --invert-match
Invert the sense of matching, to select non-matching lines. (-v is
specified by POSIX.)of matching, to select non-matching lines. (-v is
specified by POSIX.)

关于shell - (shell) 如何从一个文件中删除可以在另一个文件中找到的字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2380040/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com