将在Linux的数字之间的分隔符 [英] Insert delimiter between digits in linux

查看:255
本文介绍了将在Linux的数字之间的分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我从数据库中检索一些随机数。例如:

  12203770
6458251
6458250
10336719
10366878
10366877
10366874
81048

现在,我已经置身其中间的分隔符/。我使用这个命令:

  [根@ abc01〜]#的awk'BEGIN {FS =; OFS =/} {打印$ 1,$ 2,$ 3,$ 4,$ 5}'的/ tmp /的abc.txt

如果数字是8位数,但我的要求是能正常工作:
命令/脚本应当从权利,休息留下最后3位,它打印数字与分隔符。

要求所需的输出:

  1/2/2/0/3
6/4/5/8
6/4/5/8
1/0/3/3/6
1/0/3/6/6
1/0/3/6/6
1/0/3/6/6
8/1

请帮助。


解决方案

 的awk'BEGIN {FS =; OFS =/} {NF-= 3;打印}'文件
1/2/2/0/3
6/4/5/8
6/4/5/8
1/0/3/3/6
1/0/3/6/6
1/0/3/6/6
1/0/3/6/6
8/1

I have few random numbers which I retrieve from a database. Eg.

12203770
6458251
6458250
10336719
10366878
10366877
10366874
81048

Now, I have to place the delimiter "/" in between them. I am using this command:

[root@abc01 ~]#  awk 'BEGIN{FS="";OFS="/"} {print $1,$2,$3,$4,$5}' /tmp/abc.txt

This works fine if numbers are 8 digits but my requirement is : The command/script should leave last 3 digit from right and for rest, it prints digit with delimiter.

Desired output required:

1/2/2/0/3
6/4/5/8
6/4/5/8
1/0/3/3/6
1/0/3/6/6
1/0/3/6/6
1/0/3/6/6
8/1

Kindly help.

解决方案

awk 'BEGIN{FS="";OFS="/"}{NF-=3;print}' file
1/2/2/0/3
6/4/5/8
6/4/5/8
1/0/3/3/6
1/0/3/6/6
1/0/3/6/6
1/0/3/6/6
8/1

这篇关于将在Linux的数字之间的分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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