I have a file containing numbers in it say numbers.txt as follows.
9374541632553 51243747879841 32030098896914 84654557358238 11000656847765
I want to convert it to the following format.
<item>9 3 7 4 5 4 1 6 3 2 5 5 3 <tag>out="9374541632553"
<item>5 1 2 4 3 7 4 7 8 7 9 8 4 1 <tag>out="51243747879841"
<item>3 2 0 3 0 0 9 8 8 9 6 9 1 4 <tag>out="32030098896914"
<item>8 4 6 5 4 5 5 7 3 5 8 2 3 8 <tag>out="84654557358238"
<item>1 1 0 0 0 6 5 6 8 4 7 7 6 5 <tag>out="11000656847765"
I'am using following command to convert it.
cat numbers.txt | while read line; do sed -r "s/([0-9])/\1/g; s/([0-9])/\1 /g ; s/^/<item>/g; s/$/<tag>out="\$line/g" ; done
But output I'am getting is as follows:
<item>5 1 2 4 3 7 4 7 8 7 9 8 4 1 <tag>out="9374541632553
<item>3 2 0 3 0 0 9 8 8 9 6 9 1 4 <tag>out="9374541632553
<item>8 4 6 5 4 5 5 7 3 5 8 2 3 8 <tag>out="9374541632553
<item>1 1 0 0 0 6 5 6 8 4 7 7 6 5 <tag>out="9374541632553
<item>3 3 2 1 6 7 8 2 0 9 3 8 4 2 <tag>out="9374541632553
Anyone can you please tell me why only 1st line is getting printed at last column instead of line by line value.
And what about 1st line in output?
Explain the required command to desired output.