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

前端之家收集整理的这篇文章主要介绍了bash – 将数字添加到文件中每行的开头前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如何在文件中的每一行的开头添加数字?

例如。:

  1. This is
  2. the text
  3. from the file.

成为:

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

猜你在找的Bash相关文章