awk输出中的多余空间 [英] Extra space in awk output

查看:41
本文介绍了awk输出中的多余空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的示例中,为什么在分隔符前后获得空白?

Why do I get the white space before and after the delimiter in the following example?

awk -F'^'  '{print $1,":",$2}' SERVER_2012-02-29-12-15-00
3969 : 1272
3969 : 1272
3969 : 1272

我希望以下结果没有空格:

I expect the results as below without any space:

3969:1272
3969:1272
3969:1272

文本文件看起来像这样...

The text file looks like this...

cat SERVER_2012-02-29-12-15-00
3969^1272^14.140.90.242^^IN^como^2012-02-29
3969^1272^14.140.90.242^^IN^como^2012-02-29
3969^1272^14.140.90.242^^IN^como^2012-02-29

推荐答案

这可能对您有用:

awk -F'^'  '{print $1":"$2}' SERVER_2012-02-29-12-15-00
3969:1272
3969:1272
3969:1272

要用串联字段:除去.

或将输出字段分隔符 OFS 更改为null.

Or change the output field separator OFS to null.

awk -F'^' -vOFS='' '{print $1",:,"$2}' SERVER_2012-02-29-12-15-00
3969:1272
3969:1272
3969:1272

这篇关于awk输出中的多余空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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