反斜线GAWK领域 [英] backslash in gawk fields

查看:127
本文介绍了反斜线GAWK领域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚被拍成检查与GAWK我所有的输出文件,我作为避免尽我所能。
如何

I've just been made into checking all my output files with gawk which I avoid as much as I can. How does

gawk 'NF \!= 6' file

gawk 'NF != 6' file 

这就是,如何反斜杠改变这种前pression意思?

that is, how does the backslash change the meaning of this expression?

应该把它输出线比6不同领域的数量和反斜线结束?

Should it output lines with number of fields different than 6 and ending with backslash?

我收到以下错误在我的文件:

I'm getting the following error on my files:

gawk:    ^ backslash not last character on line

别人吗?

推荐答案

如果您使用双引号代替单引号,然后是一个特殊字符,应进行转义反斜杠。重要的是,你在逃避感叹号让你的的没有看到它。

If you use double quotes instead of single quotes then ! is a special character and should be escaped with a backslash. Importantly, you are escaping the exclamation point so that your shell does not see it.

gawk "NF \!= 6" file

在双引号外壳将转换 \\!传递给呆呆地看着前面的参数。反斜杠由gawk的调用时间了。

Within double quotes the shell will convert \! to ! before passing the argument to gawk. The backslash is gone by the time gawk is invoked.

通过单一qutoes,虽然外壳会忽略字符,所以没有必要用反斜杠转义。事实上,当你发现这是一个语法错误这样做,因为反斜线最终被传递到呆子,这barfs的意外 \\

With single qutoes, though, the shell will ignore ! characters, so there's no need to escape them with backslashes. In fact, as you found out it is a syntax error to do so since the backslash ends up being passed to gawk, which barfs on the unexpected \.

这篇关于反斜线GAWK领域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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