copying to the end of the line

Hi,
I have a file as such

1 <text1><text2></
2 <text3><text4></
3 <text5><text6></
4 <text7><text8></

I need is so the first bit of text in the line is at the end as its xml so

1 <text1><text2></text1>
2 <text3><text4></text3>
3 <text5><text6></text5>
4 <text7><text8></text7>

Anyone know a way I can do this?

Thanks for any help you can give

Like this?

echo '<text1><text2></' | awk -F '<' '{print $0$2}'
1 Like

Input:

$ cat file
1 <text1><text2></
2 <text3><text4></
3 <text5><text6></
4 <text7><text8></

Output:

$  awk -F '[<.*>]' '{print $0 $2">"}' file
1 <text1><text2></text1>
2 <text3><text4></text3>
3 <text5><text6></text5>
4 <text7><text8></text7>

Guru

1 Like

thanks alot the awk one worked a dream :slight_smile:

great work
:smiley:

Through Sed..

sed 's/\([a-z][a-z0-9]*>\).*/&\1/' inputfile

One more question i promise :slight_smile:

I have this

<A="B/C/D"/><E="F" G="H"><![i]]></

and i need to get rid of the last bit <![i]]></ and also move the / from the end of the first <> to the end of the second.

<A="B/C/D"><E="F" G="H"/>

Any help would be much apprenciated :slight_smile:

echo '<A="B/C/D"/><E="F" G="H"><!]></' | sed -e 's#><!\]>.*$#/>#g' -e 's#/>#>#1'
<A="B/C/D"><E="F" G="H"/>

--ahamed

sed 's#><!\]></#/>#' yourfile

only the opening square backet must be escaped (escaping the closing bracket is useless)

$ cat f1
<A="B/C/D"/><E="F" G="H"><!]></
$ sed 's#><!\]></#/>#' f1
<A="B/C/D"/><E="F" G="H"/>

Hi,
could you explain how this command works?
Especially this part "&\1".
Thanks

s/.../.../

the & refer to what has previously been matched in the whole pattern space (here within the first /.../ )

This example would put the third column at the firt column:
s/\(...\)\(...\)\(...\)/\3\1\2/

The \1 refer to what has previously been matched in the first parenthesis of the pattern space \(...\)

1 Like

I'm having a little trouble, this is my fault as i got the code slightly wrong

line number <A="B/C/D"/><E="F" G="H"><![[i]]></

I forgot to mention the line number is in it which i need keeping and also there is an extra [ in the last string. I have tried everything I can think of from editing what I was given to trying my own code.
Is there anything else you can think of??
Thanks

echo '123 <A="B/C/D"/><E="F" G="H"><![]></' | sed -e 's#><!\[\]>.*$#/>#g' -e 's#/>#>#1'

--ahamed

Still not quite there :frowning:

I don't think ive been incredibly clear thats my fault but the A B C etc are not actually that in the file I need the script to be able to work when these are different each time