I have more than 100 files with with over 9000 lines of text. A preview extract of one of the files looks like this:
<productname>kidscar1</productname>
<productid>98</productid>
<productname>kidscar2</productname>
<productcolor>yellow</productcolor>
<productid>101</productid>
<productname>kidscar3</productname>
<productsize>xxl</productsize>
<productcolor>green</productcolor>
<productid>104</productid>
<productname>kidscar4</productname>
<productcolor>bleu</productcolor>
<productsize>xl</productsize>
<producttype>electric</producttype>
<productid>103</productid>
I'm trying to change (re-arange) the product ID's starting from a different product ID and automatically count this up for the next lines containing an product ID.
I was thinking of a shell script solution which I could use in a for loop.
**sh idscript.sh oldfile.txt 1000 productid > newfile.txt**
Result:
<productname>kidscar1</productname>
<productid>1000</productid>
<productname>kidscar2</productname>
<productcolor>yellow</productcolor>
<productid>1001</productid>
<productname>kidscar3</productname>
<productsize>xxl</productsize>
<productcolor>green</productcolor>
<productid>1002</productid>
<productname>kidscar4</productname>
<productcolor>bleu</productcolor>
<productsize>xl</productsize>
<producttype>electric</producttype>
<productid>1003</productid>`
I know that it's possible to replace a whole line in sed with the next command:
**sed "s/<productid>100</productid>=.*/<productid>=<productid>1000</productid>/g"**
But how can I make this work to get the above result? If there are other (simpler) ways to achieve this, i like to hear it also!