mass rename with sed
I have to work with a huge XML-File which was exported from Excel.
The file looks like this:
<Row>
<Data>some data..</Data>
<Data>some data..</Data>
<Data>some data..</Data>
<Data>some data..</Data>
<Data>some data..</Data>
<Data>some data..</Data>
<Data>some data..</Data>
<Row>
There are about 2000 Row-elements.
So there is always one Row-tag with 7 Data-subtags. Now I'd like to rename every first Data-tag to 'one', the second one to 'second' and so on..
What's the correct sed syntax to do this开发者_如何学C?
Consider using awk instead...
BEGIN {
NUM[1]="one"
NUM[2]="two"
NUM[3]="three"
NUM[4]="four"
NUM[5]="five"
NUM[6]="six"
NUM[7]="seven"
}
/<Row/{
print
for(i=1;i<8;i++) {
getline
sub(/Data/, NUM[i]);print
}
}
/<\/Row/{print}
Output:
$ awk -f r.awk input
<Row>
<one>some data..</one>
<two>some data..</two>
<three>some data..</three>
<four>some data..</four>
<five>some data..</five>
<six>some data..</six>
<seven>some data..</seven>
</Row>
精彩评论