本文介绍了sed增量编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用增量值替换一些文本.考虑文件xx:
I'd like to substitute some text with an incremental value.Considering file xx:
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
和sed命令:
for n in seq 3;do sed -e 's/<RecordID>\d/<RecordID>'`echo $n`'/' xx; done
echo $n
命令不会递增.
也尝试过
n=1; sed -e 's/<RecordID>/<RecordID>'`echo $n ;let n=$n+1`'/g' xx
但没有成功.
仅考虑sed(没有awk或perl),如何使RecordID字段增加,如:
Considering only sed (no awk or perl) how can I have the RecordID field incremented as in:
<outro>dfdfd</outro>
<RecordID>1</RecordID>
<outro>dfdfd</outro>
<RecordID>2</RecordID>
<outro>dfdfd</outro>
<RecordID>3</RecordID>
<outro>dfdfd</outro>
推荐答案
while read line; do n=$((++n)) && echo $line|sed -e 's/[0-9]/'$(($n))'/' ; done < patt
这篇关于sed增量编号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!