3

I've encountered the following problem: I need to add space at certain position in each line, to transform data from

ATOM      1 HT1 GLY     5      10.346  30.927 130.252  0.00  0.00

to (by adding space in 12th column)

ATOM      1  HT1 GLY     5      10.346  30.927 130.252  0.00  0.00

Now I've managed to achieve it with:

cat $INFILE | cut -c-11 > $INFILE.1
cat $INFILE | cut -c12- > $INFILE.2
paste -d ' ' $INFILE.1 $INFILE.2 > $INFILE

But may be there is more elegant solution, without using temporary files?

Thanks in advance.

aland
  • 3,066
  • 18
  • 26

1 Answers1

3

You can certainly do this with sed but I know perl better ...

  perl -p -i -e 's/^(.{12})/$1 /' $INFILE

Later

  sed -i -e 's/^.\{12\}/& /' $INFILE
aland
  • 3,066
  • 18
  • 26