我有两个文件。File1
包含一些句子,并File2
包含我想要保留的行号File1
。
例如,File1
:
He is a boy.
She is a cook.
Okay.
She went to school.
She is pretty.
Run Code Online (Sandbox Code Playgroud)
File2
:
1
4
Run Code Online (Sandbox Code Playgroud)
输出:
He is a boy.
She went to school.
Run Code Online (Sandbox Code Playgroud)
有没有办法可以使用sed
, grep
, 或 来做到这一点awk
?我不想像这里一样手动编写行号。
我有一个文件,其中包含彼此下的单词列表,其中这些单词属于一个句子,然后属于下一个句子的单词也彼此在下。与一个句子相关的单词块后跟一个空格,如下面的表示#2 所示
预期输出:(表示#1):
These are the words for sentence 1
These are the words for sentence 2
Run Code Online (Sandbox Code Playgroud)
预期输入:(表示#2):
These
are
the
words
for
sentence 1
these
are
the
words
for
sentence 2
Run Code Online (Sandbox Code Playgroud)
我尝试遵循这个问题,但是当我对不同的句子使用不同的单词时,它不起作用,那么如何在linux中将表示编号2更改为表示编号1?