如果一行包含超过 3 个空格,请删除该行
我有一个文本文件,
sadsadsad sadsadsadd sadasdsadad
其中的一些行在第二列中间包含一个附加空格,例如
sadsadsad sads adsadd sadasdsadad
Can I use awk to view the file and delete the line if there's more more space on a certain line ?
I have a text file in the form
sadsadsad sadsadsadd sadasdsadad
some of the lines in there contain an addition space in the middle of the second column such as
sadsadsad sads adsadd sadasdsadad
Can I use awk to look at the file and delete the line if there's more than 2 spaces on a particular line?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要
awk
为此,一个简单的sed
就可以:您特别想要
awk
,您可以执行以下操作:如果 还可以自定义正则表达式以使其更精确,也许在两种情况下都使用
/ [^ ]+ [^ ]+ /
。或者甚至,正如 jkerian 在另一个答案中建议的那样,只需使用 NF 即可。You don't need
awk
for that, a simplesed
will do:If you want
awk
specifically, you can do something like this:You can also customize the regexp to be more precise, maybe by using in both cases
/ [^ ]+ [^ ]+ /
. Or even, as jkerian proposes in another answer, just useNF
.您可能可以创建一个正则表达式来使用 sed 或 awk 的正则表达式匹配来执行此操作...但这有效
另一种选择是使用 NF 变量
There's probably a regex you can create to do this with a regex match with sed or awk... but this works
Another alternative is to use the NF variable