Insert space in a word using sed

Hi all,

I have a file that looks like this-

-----------------------------

.
.
ATOM      8  O2'    U A   5     135.452 109.687   7.148  1.00  48.99      A16S 
ATOM      9  C1'    U A   5     135.282 111.512   5.641  1.00  48.99      A16S 
ATOM     10  N1    U A   5     134.647 112.595   6.411  1.00106.22      A16S 
ATOM     11  C2    U A   5     135.070 112.783   7.722  1.00106.22      A16S 
ATOM     12  O2    U A   5     135.933 112.100   8.250  1.00106.22      A16S 
.
.

-----------------------------

The problem with the file is the lack of space between columns 10 and 11 in certain rows (underlined) which is making parsing a bit difficult.

I used sed to insert space between these fields using this command-

sed 's/1.00\([0-9]\).*\.[0-9]\{2\}/1.00 [0-9].*\.[0-9]\{2\}/' file.txt

but the output i got was-

--------------------------------

ATOM     12  O2    U A   5     135.933 112.100   8.250  1.00 [0-9].*.[0-9]{2}      A16S 
ATOM     12  O2    U A   5     135.933 112.100   8.250  1.00 [0-9].*.[0-9]{2}      A16S 
ATOM     12  O2    U A   5     135.933 112.100   8.250  1.00 [0-9].*.[0-9]{2}      A16S 

---------------------------

I am relatively new to sed/awk. Please suggest a way to go about it.

Thanks,

Hi, try this adaptation:

sed 's/1\.00\([0-9]*\.[0-9]\{2\}\)/1.00 \1/' file
1 Like

To make sure you don't substitute an arbitrary 1.00 somewhere on the line, and allow for field 10 to assume values other than 1.00, try

awk 'NF != 12 {T = $(NF-1); sub (/\.[0-9][0-9]/, "& ", T); sub ($(NF-1), T)} 1' file
1 Like