sed - remove space and . for a pattern

Hi,

I have file which contains following lines

A| 965.|Mr.|35.45| 66.
B| 33.| a456.| 77.

The output should be

A|965|Mr.|35.45|66
B|33| a456.|77

Basically if a Number has space in prefix and . in suffix remove both.
So pattern could be if there is a | which has next two characters as space and number ending with a number.| remove space and .

The line below removes dot if "number.|" pattern occurs

sed -i -e 's/\ ([0-9]\).|/\1|/g' -e 's/\ ([0-9]\).$/\1/' file

I need something to search for
"| number" and make it |number

Thanks

---------- Post updated at 05:19 PM ---------- Previous update was at 04:06 PM ----------

Hi,

I almost got what I wanted:

sed -i -e 's/\([0-9]\).|/\1|/g' -e 's/\([0-9]\).$/\1/' -e 's/|\s\([0-9]\)/|\1/g' file

This one works with your example:

sed 's/ \([0-9][0-9]*\)\./\1/g' file

---------- Post updated at 05:44 PM ---------- Previous update was at 05:36 PM ----------

This one works according to your description:

sed 's/^/|/; s/$/|/; s/| \([0-9][0-9]*\)\.|/|\1|/g; s/^|//; s/|$//' file

It treats the following example line differently:

A|965|Mr. 90.|35.45|66
1 Like