Sed command not working

Hi,

I have a test file as follows:

1G102119 ^ AA1179291 ^ 06oct2006 09:50:35^ 73.4^ 2^ 13^ 0^ 1493
1G102119 ^ AA1179291 ^ 06oct2006 09:49:45^ 73.4^ 2^ 13^ 0^ 1493
1G102119 ^ AA1179291 ^ 06oct2006 09:48:58^ 73.4^ 2^ 17^ 0^ 2
1G102119 ^ AA1179291 ^ 06oct2006 09:48:58^ 73.4^ 2^ 17^ 0^ 21

I am striping of blank spaces using the following sed command.

cat test | sed -e 's/ *^/^/g' | sed -e 's/\^ */^/g' | sed -e 's/ *$//g' | sed -e 's/\.^/^/g' | sed -e 's/\^.$/^/g' > test.new

I am getting the results as follows:

1G102119^AA1179291^06oct2006 09:50:35^73.4^2^13^0^1493
1G102119^AA1179291^06oct2006 09:49:45^73.4^2^13^0^1493
1G102119^AA1179291^06oct2006 09:48:58^73.4^2^17^0^
1G102119^AA1179291^06oct2006 09:48:58^73.4^2^17^0^21

But if you notice, the third record is having a value missed at the end. The value 2 is missing.

What is wrong with the script.

Thanks.

I was able to come over this problem by using the following sed command

sed -e 's/ *$/ /g' instead of sed -e 's/ *$//g'

But I don't understand the need of space between the forward slashes.

Thanks.. :confused:

This sed should be simpler

sed -e "s/[ ]*^[ ]*/^/g" input.txt

Thanks for the reply Vino...

But that sed command is not able to produce the ouput.

[/tmp]$ echo "
1G102119 ^ AA1179291 ^ 06oct2006 09:50:35^ 73.4^ 2^ 13^ 0^ 1493
1G102119 ^ AA1179291 ^ 06oct2006 09:49:45^ 73.4^ 2^ 13^ 0^ 1493
1G102119 ^ AA1179291 ^ 06oct2006 09:48:58^ 73.4^ 2^ 17^ 0^ 2
1G102119 ^ AA1179291 ^ 06oct2006 09:48:58^ 73.4^ 2^ 17^ 0^ 21" | sed -e 's/ *^/^/g' | sed -e 's/\^ */^/g' | sed -e 's/ *$/ /g' | sed -e 's/\.^/^/g' | sed -e 's/\^.$/^/g' 
1G102119^AA1179291^06oct2006 09:50:35^73.4^2^13^0^1493 
1G102119^AA1179291^06oct2006 09:49:45^73.4^2^13^0^1493 
1G102119^AA1179291^06oct2006 09:48:58^73.4^2^17^0^2 
1G102119^AA1179291^06oct2006 09:48:58^73.4^2^17^0^21 
[/tmp]$ echo "
1G102119 ^ AA1179291 ^ 06oct2006 09:50:35^ 73.4^ 2^ 13^ 0^ 1493
1G102119 ^ AA1179291 ^ 06oct2006 09:49:45^ 73.4^ 2^ 13^ 0^ 1493
1G102119 ^ AA1179291 ^ 06oct2006 09:48:58^ 73.4^ 2^ 17^ 0^ 2
1G102119 ^ AA1179291 ^ 06oct2006 09:48:58^ 73.4^ 2^ 17^ 0^ 21" | sed -e "s/[ ]*^[ ]*/^/g"
1G102119^AA1179291^06oct2006 09:50:35^73.4^2^13^0^1493
1G102119^AA1179291^06oct2006 09:49:45^73.4^2^13^0^1493
1G102119^AA1179291^06oct2006 09:48:58^73.4^2^17^0^2
1G102119^AA1179291^06oct2006 09:48:58^73.4^2^17^0^21
[/tmp]$ 

I dont understand what is missing. The first sed command is yours. The second one gives the same result.

My mistake...

Thanks a lot Vino...

Hi Vino,

Can you also please help me in eliminating the dot as well using ur simpler sed command.

From

0EI0LAFV^0EI0L46V^.^2^7^.^40000^J^.^.^.^

To

0EI0LAFV^0EI0L46V^^2^7^^40000^J^^^

Thanks

It can be done by the following command. Is there much simpler and faster?

cat test | sed -e "s/[ ]^[ ]/^/g" | sed -e "s/\.^/^/g" > test.new

Thanks

Congratulations, that's a UUOC.

Try:

sed -e "s/[ ]*^[ ]*/^/g" | sed -e "s/\.^/^/g" > test.new < test

Isnt that one sed far too many ?

sed -e "s/[ ]*^[ ]*/^/g" -e "s/\.//g" > test.new < test

or

sed -e "s/[ ]*^[ ]*/^/g;s/\.//g" > test.new < test

Pick your choice.