> For the complete documentation index, see [llms.txt](https://valineliu.gitbook.io/deuterium-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valineliu.gitbook.io/deuterium-wiki/linux/awk-1/shan-chu-kong-hang.md).

# 删除空行

比如一个文件 ：

{% code title="file\_with\_blanks" %}

```bash


a

b
c

d



```

{% endcode %}

要删除所有的空行，可以这样：

```bash
awk 'NF>0' file_with_blanks
```

结果如下：

```bash
a
b
c
d
```

还可以将命令保存在脚本中：

{% code title="delete\_blank\_lines.awk" %}

```bash
#! /usr/bin/awk -f
NF > 0
```

{% endcode %}
