【发布时间】:2018-05-14 10:12:16
【问题描述】:
我有两个文件:
1.txt
/stackoverflow.com/questions
/stackoverflow.com/reports
/stackoverflow.com/answers
2.txt
/stackoverflow.com/questions/18959800/grep-each-line-from-a-file-in-another-file
/stackoverflow.com/answers/18984800/grep-each-line-from
/stackoverflow.com/questions/20559800/line-from-a-file-in-another-file
/stackoverflow.com/ask/9959800/file-in-another-file-second_line
如果来自 1.txt 的行是来自 2.txt 的行的一部分,则打印此行。 如果 2.txt 中的一行不匹配,则打印此行。
我想得到这样的 output.txt 文件:
输出.txt:
/stackoverflow.com/questions/
/stackoverflow.com/reports/
/stackoverflow.com/answers/
/stackoverflow.com/ask/9959800/file-in-another-file-second_line
可以将所有行放在一个文件中:
/stackoverflow.com/questions
/stackoverflow.com/reports
/stackoverflow.com/answers
/stackoverflow.com/questions/18959800/grep-each-line-from-a-file-in-another-file
/stackoverflow.com/answers/18984800/grep-each-line-from
/stackoverflow.com/questions/20559800/line-from-a-file-in-another-file
/stackoverflow.com/ask/9959800/file-in-another-file-second_line
【问题讨论】:
-
你确定
output.txt?如果是这样,请更好地解释逻辑。 -
欢迎来到 Stack Overflow!抱歉,这不是 StackOverflow 的工作方式。 “我想做 X,请给我提示和/或示例代码”形式的问题被认为是题外话。请访问help center并阅读How to Ask,尤其是阅读Why is “Can someone help me?” not an actual question?