linux系统中awk命令输出等宽的行号

 

1、直接测试

root@DESKTOP-1N42TVH:/home/test2# ls
a.txt
root@DESKTOP-1N42TVH:/home/test2# cat a.txt
d g u k
d g u k
s d g c
s d g c
x v d e
x v d e
s q e t
s q e t
c g e g
c g e g
root@DESKTOP-1N42TVH:/home/test2# awk '{print NR, $0}' a.txt        ##  直接输出行号
1 d g u k
2 d g u k
3 s d g c
4 s d g c
5 x v d e
6 x v d e
7 s q e t
8 s q e t
9 c g e g
10 c g e g
root@DESKTOP-1N42TVH:/home/test2# awk '{printf("%02g %s\n", NR, $0)}' a.txt    ## 输出等宽的行号
01 d g u k
02 d g u k
03 s d g c
04 s d g c
05 x v d e
06 x v d e
07 s q e t
08 s q e t
09 c g e g
10 c g e g

 

posted @ 2022-04-03 22:55  小鲨鱼2018  阅读(153)  评论(0编辑  收藏  举报