1
ATOM 9996 CG GLU 622 -13.525 -7.714 -11.215 0.0136 1.9080 0.1094 ATOM 9997 2HG GLU 622 -12.773 -7.608 -11.999 -0.0425 1.4870 0.0157 ATOM 9998 3HG GLU 622 -13.121 -8.370 -10.441 -0.0425 1.4870 0.0157 ATOM 9999 CD GLU 622 -14.803 -8.348 -11.783 0.8054 1.9080 0.0860 ATOM 10000 OE1 GLU 622 -15.541 -9.019 -11.024 -0.8188 1.6612 0.2100 ATOM 10001 OE2 GLU 622 -15.105 -8.223 -12.988 -0.8188 1.6612 0.2100 ATOM 10002 C GLU 622 -13.072 -4.215 -9.499 0.5366 1.9080 0.0860 ATOM 10003 O GLU 622 -13.537 -3.437 -10.330 -0.5819 1.6612 0.2100 ATOM 10004 N TYR 623 -12.988 -3.858 -8.210 -0.4157 1.8240 0.1700 ATOM 10005 H TYR 623 -12.684 -4.551 -7.536 0.2719 0.6000 0.0157 ATOM 10006 CA TYR 623 -13.410 -2.540 -7.700 -0.0014 1.9080 0.1094 ATOM 10007 HA TYR 623 -13.794 -1.927 -8.513 0.0876 1.3870 0.0157 ATOM 10008 CB TYR 623 -14.530 -2.720 -6.667 -0.0152 1.9080 0.1094 ATOM 10009 2HB TYR 623 -14.107 -3.312 -5.863 0.0295 1.4870 0.0157 ATOM 10010 3HB TYR 623 -14.784 -1.738 -6.265 0.0295 1.4870 0.0157 ATOM 10011 CG TYR 623 -15.831 -3.390 -7.081 -0.0011 1.9080 0.0860 ATOM 10012 CD1 TYR 623 -16.301 -3.357 -8.410 -0.1906 1.9080 0.0860 

As seen in the format above, the lines after 10000 ATOM are shown with one space shift. How can I specifically remove just one space before the second column in the file after line number 10000?

Tho output should be like:

ATOM 9995 3HB GLU 622 -14.203 -5.702 -11.411 -0.0173 1.4870 0.0157 ATOM 9996 CG GLU 622 -13.525 -7.714 -11.215 0.0136 1.9080 0.1094 ATOM 9997 2HG GLU 622 -12.773 -7.608 -11.999 -0.0425 1.4870 0.0157 ATOM 9998 3HG GLU 622 -13.121 -8.370 -10.441 -0.0425 1.4870 0.0157 ATOM 9999 CD GLU 622 -14.803 -8.348 -11.783 0.8054 1.9080 0.0860 ATOM 10000 OE1 GLU 622 -15.541 -9.019 -11.024 -0.8188 1.6612 0.2100 ATOM 10001 OE2 GLU 622 -15.105 -8.223 -12.988 -0.8188 1.6612 0.2100 ATOM 10002 C GLU 622 -13.072 -4.215 -9.499 0.5366 1.9080 0.0860 ATOM 10003 O GLU 622 -13.537 -3.437 -10.330 -0.5819 1.6612 0.2100 ATOM 10004 N TYR 623 -12.988 -3.858 -8.210 -0.4157 1.8240 0.1700 ATOM 10005 H TYR 623 -12.684 -4.551 -7.536 0.2719 0.6000 0.0157 ATOM 10006 CA TYR 623 -13.410 -2.540 -7.700 -0.0014 1.9080 0.1094 ATOM 10007 HA TYR 623 -13.794 -1.927 -8.513 0.0876 1.3870 0.0157 ATOM 10008 CB TYR 623 -14.530 -2.720 -6.667 -0.0152 1.9080 0.1094 ATOM 10009 2HB TYR 623 -14.107 -3.312 -5.863 0.0295 1.4870 0.0157 ATOM 10010 3HB TYR 623 -14.784 -1.738 -6.265 0.0295 1.4870 0.0157 ATOM 10011 CG TYR 623 -15.831 -3.390 -7.081 -0.0011 1.9080 0.0860 ATOM 10012 CD1 TYR 623 -16.301 -3.357 -8.410 -0.1906 1.9080 0.0860 
1
  • Are you sure you want to? That would make 10009 2HB into 100092HB. Or are the lines 10009 and 10010 wrong? Don't you want there to always be one space after the residue number? Your desired output sometimes has an extra character on the left and sometimes on the right? Don't you want all of them to be aligned? Commented May 9, 2016 at 11:35

2 Answers 2

1

Using sed:

sed '/ATOM *10000/,$ s/ATOM \( *\)\([0-9]*\)/ATOM\1\2/' 

It uses an address range, from /ATOM *10000/ to $, which stand for the first line matching ATOM + spaces + 10000, and the last line, respectively.

For each line in the address range, it replaces the ATOM followed by spaces, the number by everything ATOM, spaces without the first one, and the number.

0
0

There are many ways of doing this. You could read the file and remove the space on all lines after whose second field is greater than 9999:

$ awk '$2>9999{sub(/ /,"")}1;' file ATOM 9996 CG GLU 622 -13.525 -7.714 -11.215 0.0136 1.9080 0.1094 ATOM 9997 2HG GLU 622 -12.773 -7.608 -11.999 -0.0425 1.4870 0.0157 ATOM 9998 3HG GLU 622 -13.121 -8.370 -10.441 -0.0425 1.4870 0.0157 ATOM 9999 CD GLU 622 -14.803 -8.348 -11.783 0.8054 1.9080 0.0860 ATOM 10000 OE1 GLU 622 -15.541 -9.019 -11.024 -0.8188 1.6612 0.2100 ATOM 10001 OE2 GLU 622 -15.105 -8.223 -12.988 -0.8188 1.6612 0.2100 ATOM 10002 C GLU 622 -13.072 -4.215 -9.499 0.5366 1.9080 0.0860 ATOM 10003 O GLU 622 -13.537 -3.437 -10.330 -0.5819 1.6612 0.2100 ATOM 10004 N TYR 623 -12.988 -3.858 -8.210 -0.4157 1.8240 0.1700 ATOM 10005 H TYR 623 -12.684 -4.551 -7.536 0.2719 0.6000 0.0157 ATOM 10006 CA TYR 623 -13.410 -2.540 -7.700 -0.0014 1.9080 0.1094 ATOM 10007 HA TYR 623 -13.794 -1.927 -8.513 0.0876 1.3870 0.0157 ATOM 10008 CB TYR 623 -14.530 -2.720 -6.667 -0.0152 1.9080 0.1094 ATOM 10009 2HB TYR 623 -14.107 -3.312 -5.863 0.0295 1.4870 0.0157 ATOM 10010 3HB TYR 623 -14.784 -1.738 -6.265 0.0295 1.4870 0.0157 ATOM 10011 CG TYR 623 -15.831 -3.390 -7.081 -0.0011 1.9080 0.0860 ATOM 10012 CD1 TYR 623 -16.301 -3.357 -8.410 -0.1906 1.9080 0.0860 

Alternatively, you can align everything:

$ perl -lane 'printf "%-5s%6s %-3s%4s%5d%8s%8s%8s%8s%8s\n",@F' file ATOM 9996 CG GLU 622 -13.525 -7.714 -11.215 0.0136 1.9080 ATOM 9997 2HG GLU 622 -12.773 -7.608 -11.999 -0.0425 1.4870 ATOM 9998 3HG GLU 622 -13.121 -8.370 -10.441 -0.0425 1.4870 ATOM 9999 CD GLU 622 -14.803 -8.348 -11.783 0.8054 1.9080 ATOM 10000 OE1 GLU 622 -15.541 -9.019 -11.024 -0.8188 1.6612 ATOM 10001 OE2 GLU 622 -15.105 -8.223 -12.988 -0.8188 1.6612 ATOM 10002 C GLU 622 -13.072 -4.215 -9.499 0.5366 1.9080 ATOM 10003 O GLU 622 -13.537 -3.437 -10.330 -0.5819 1.6612 ATOM 10004 N TYR 623 -12.988 -3.858 -8.210 -0.4157 1.8240 ATOM 10005 H TYR 623 -12.684 -4.551 -7.536 0.2719 0.6000 ATOM 10006 CA TYR 623 -13.410 -2.540 -7.700 -0.0014 1.9080 ATOM 10007 HA TYR 623 -13.794 -1.927 -8.513 0.0876 1.3870 ATOM 10008 CB TYR 623 -14.530 -2.720 -6.667 -0.0152 1.9080 ATOM 10009 2HB TYR 623 -14.107 -3.312 -5.863 0.0295 1.4870 ATOM 10010 3HB TYR 623 -14.784 -1.738 -6.265 0.0295 1.4870 ATOM 10011 CG TYR 623 -15.831 -3.390 -7.081 -0.0011 1.9080 ATOM 10012 CD1 TYR 623 -16.301 -3.357 -8.410 -0.1906 1.9080 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.