如何忽略用awk空行和注释行 [英] how to ignore blank lines and comment lines using awk

查看:1287
本文介绍了如何忽略用awk空行和注释行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写这篇code:

awk -F'=' '!/^$/{arr[$1]=$2}END{for (x in arr) {print x"="arr[x]}}' 1.txt 2.txt

这code忽略空白行,但我也想忽略行以#(注释)开始。

this code ignore blank lines, but i also want to ignore line starting with # (comments).

不知道如何添加多个模式?

Any idea how to add multiple patterns?

推荐答案

修改!/ ^ $ /

!/^($|#)/

!/^($|[:space:]*#)/

如果你想忽略空格前的

if you want to disregard whitespace before the #.

这篇关于如何忽略用awk空行和注释行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆