Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

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
share|improve this answer
    
sed also knows about {}, but needs escaping: sed -i 's/.\{12\}/& /' $INFILE` works. –  Daniel Andersson May 8 '12 at 14:22
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.