加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 将数字添加到文件中每行的开头

发布时间:2020-12-15 20:03:55 所属栏目:安全 来源:网络整理
导读:如何在文件中的每一行的开头添加数字? 例如。: This isthe textfrom the file. 成为: 000000001 This is000000002 the text000000003 from the file. AWK的printf,NR和$ 0使得对格式化的精确和灵活控制变得容易: ~ $ awk '{printf("%010d %sn",NR,$0)}
如何在文件中的每一行的开头添加数字?

例如。:

This is
the text
from the file.

成为:

000000001 This is
000000002 the text
000000003 from the file.
AWK的printf,NR和$ 0使得对格式化的精确和灵活控制变得容易:
~ $ awk '{printf("%010d %sn",NR,$0)}' example.txt
0000000001 This is
0000000002 the text
0000000003 from the file.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读