号码添加到每一行的开始在一个文件 [英] Add numbers to the beginning of every line in a file
本文介绍了号码添加到每一行的开始在一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎么能在一个文件中的号码加入每一行的开头?
例如:
这是
文本
从该文件。
变成了:
000000001这是
000000002文
000000003从该文件。
解决方案
AWK的的的printf 的 NR
和 $ 1,0
让您轻松拥有precise和灵活的控制格式:
〜$ AWK'{printf的(%010d%S \\ n,NR,$ 0)}'example.txt文件
0000000001这是
0000000002文
0000000003从该文件。
How can I add numbers to the beginning of every line in a file?
E.g.:
This is the text from the file.
Becomes:
000000001 This is 000000002 the text 000000003 from the file.
解决方案
AWK's printf, NR
and $0
make it easy to have precise and flexible control over the formatting:
~ $ awk '{printf("%010d %s\n", NR, $0)}' example.txt
0000000001 This is
0000000002 the text
0000000003 from the file.
这篇关于号码添加到每一行的开始在一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文