本文介绍了在shell脚本一个字符串变量递增的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个来自变量字符串
我想增加它。我怎么能做到这一点使用shell脚本?
这是我的输入它来自一个变量:
ABC-专一-01
输出应该是:
ABC-专一-02
解决方案
检查:
肯特$回声ABC-专一-07| awk的-F'-'-v OFS =' - ''{$ 3 =的sprintf(%02D,++ $ 3 )} 7'
ABC-专一-08
以上codeS做增量,让您的数字格式。
I have a string which comes from a variableI want to increment it. how can i do that using shell script?
this is my input which comes from a variable:
abc-ananya-01
output should be:
abc-ananya-02
解决方案
check this:
kent$ echo "abc-ananya-07"|awk -F'-' -v OFS='-' '{$3=sprintf("%02d",++$3)}7'
abc-ananya-08
The above codes do the increment and keep your number format.
这篇关于在shell脚本一个字符串变量递增的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!