为什么“1,4p”输出所有行而不是前四行?

Sco*_*rce 1 sed

我有一个名为“list”的文本文件,其中包含一些随机单词:

he
she
we
his
her
with
his this this -- this
this
Run Code Online (Sandbox Code Playgroud)

我运行了这个 sed 命令:

sed '1,4p' list
Run Code Online (Sandbox Code Playgroud)

我认为这个 sed 命令要做的是列出这个文件中的前 4 个单词,所以我认为输出是:

he
she
we
his
Run Code Online (Sandbox Code Playgroud)

但是输出是这样的:

he
he
she
she
we
we
his
his
her
with
his this this -- this
this
Run Code Online (Sandbox Code Playgroud)

谁能告诉我我做错了什么或为什么输出不同?

ste*_*ver 13

你忘记了 sed的默认操作是打印每个模式空间(行) - 所以抑制你需要添加-n开关的默认行为

sed -n '1,4p' list
Run Code Online (Sandbox Code Playgroud)