legolad
September 19, 2011, 7:03am
1
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
clx
September 19, 2011, 7:13am
2
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
legolad
September 19, 2011, 7:16am
4
thanks alot the awk one worked a dream
great work
Through Sed..
sed 's/\([a-z][a-z0-9]*>\).*/&\1/' inputfile
legolad
September 19, 2011, 9:18am
6
One more question i promise
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
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
ctsgnb
September 19, 2011, 9:45am
8
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
ctsgnb
September 19, 2011, 10:01am
10
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
legolad
September 19, 2011, 10:24am
11
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
legolad
September 19, 2011, 11:07am
13
Still not quite there
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