300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > Linux下为文件增加列的shell脚本

Linux下为文件增加列的shell脚本

时间:2023-08-08 17:21:45

相关推荐

Linux下为文件增加列的shell脚本

场景:linux有份文件,需要增加一列序号来标记,通过shell脚本来实现。

步骤:

1)创建一份test.txt文件,内含一列,如下:

bash-4.1$ cat test.txtabcde

2)创建脚本row_id.sh,如下:

bash-4.1$ cat row_id.sh#!/bin/shlines=$1for ((i=1;i<=$lines;i++))doecho $i>>test_id.txtdone

3)执行脚本:sh row_id.sh 5

生成5行序号,如下:

bash-4.1$ cat test_id.txt12345

4)合并两份文件,执行:

paste test_id.txt test.txt > test_and_id.txt

5)查看最终结果:

bash-4.1$ cat test_and_id.txt1 a2 b3 c4 d5 e

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。