小编M.A*_*A.G的帖子

如何使用 sed、grep 或 awk 根据另一个文件中的行号保留文件中的某些行

我有两个文件。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?我不想像这里一样手动编写行号。

grep sed awk text-processing

5
推荐指数
1
解决办法
1168
查看次数

将不同行上的单词合并为一行

我有一个文件,其中包含彼此下的单词列表,其中这些单词属于一个句子,然后属于下一个句子的单词也彼此在下。与一个句子相关的单词块后跟一个空格,如下面的表示#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?

linux grep awk text-processing

3
推荐指数
2
解决办法
801
查看次数

标签 统计

awk ×2

grep ×2

text-processing ×2

linux ×1

sed ×1