脚本
~]$ cat 1.sh #!/bin/bash hang=$(expr `cat 2.txt |wc -l` - 1) contens=$(egrep ^a aa.txt) IFS=$'\n\n' for i in $contens do sed -i "$hang a $i" 2.txt hang=$(expr $hang + 1) done
文件
~]$ cat 2.txt 1 2 3 aaasdkhfla2347923 askdf akjdfg87998fgsdfg 4
~]$ cat aa.txt aaasdkhfla2347923 askdf akjdfg87998fgsdfg b2387sdkjlfsjdf
标签:aa,shell,hang,aaasdkhfla2347923,cat,插入,循环,contens,txt From: https://www.cnblogs.com/lgwyyds/p/16954974.html