如何使用sed命令查找第一个空行并在文件中删除正则表达式[复制]

问题描述 投票:0回答:1

这个问题在这里已有答案:

我需要使用sed命令正则表达式在文本文件中找到第一个空行。

以下是我的内容


this is defile
to be cleaned
skip rest consl

在上面的内容中,我只需找到第一行是空行并删除第一行。

我使用下面的正则表达式,但它对我不起作用,它在文件中的每个地方都找到空行。

^\s*$
regex file find line is-empty
1个回答
0
投票

在Java中你做这样的事情:

Pattern pattern = Pattern.compile ("^\\s*$", Pattern.MULTILINE);
Matcher matcher = pattern.matcher ("foo\n  \nbar");
if (matcher.find()) {
    String firstEmptyLine = matcher.group();
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.