001、
root@PC1:/home/test3# ls
a.txt
root@PC1:/home/test3# cat a.txt
e r e y e u e
e e g e 3 h r
1 3 e g e y e
e s e e e e e
root@PC1:/home/test3# cp a.txt a.txt_bak
root@PC1:/home/test3# max=$(awk -F "e" '{print NF - 1}' a.txt | sort -rn | head -n 1)
root@PC1:/home/test3# echo $max
6
root@PC1:/home/test3# let loop=$max-2
root@PC1:/home/test3# echo $loop
4
root@PC1:/home/test3# for i in $(seq $loop); do sed -i 's/e/x/3' a.txt; done ## 每一行最多宝贵2个e
root@PC1:/home/test3# ls
a.txt a.txt_bak
root@PC1:/home/test3# cat a.txt ## 结果
e r e y x u x
e e g x 3 h r
1 3 e g e y x
e s e x x x x
原创文章,作者:254126420,如若转载,请注明出处:https://blog.ytso.com/tech/aiops/276354.html