Here is some example code. Your file has blank lines, i.e. things other than ATOM lines.
That is fine.
What we want is a regex that only modifies ATOM lines with a new column #2 (index 1)
In Perl it is possible for the second part of a substitution regex to be executable code.
I think this does what you want?
Note that /$1.$num++.$3, the "." is not regex "dot" it is concatenation "operator".
Perl regex is extremely powerful!
#/usr/bin/perl/ use strict; use warnings; my $num=1; while (my $line = <DATA>) { $line =~ s/^(ATOM\s+)(\d+)(.*)/$1.$num++.$3/e; #e flag means exec +ute print $line; } =Prints ATOM 1 H5T THY C 1 107.274 35.359 -9.821 0.00 0.00 N1 H ATOM 2 O5' THY C 1 107.686 36.230 -9.553 1.00 0.00 N1 O ATOM 3 C5' THY C 1 108.813 35.973 -8.710 1.00 0.00 N1 C ATOM 4 H5' THY C 1 109.513 35.493 -9.239 0.00 0.00 N1 H ATOM 5 H5'' THY C 1 108.495 35.550 -7.861 0.00 0.00 N1 H ATOM 6 N1 THY C 1 107.956 38.157 -5.232 1.00 0.00 N1 N ATOM 7 C6 THY C 1 107.862 39.006 -4.149 1.00 0.00 N1 C ATOM 8 H6 THY C 1 108.479 39.755 -3.910 0.00 0.00 N1 H ATOM 9 C2 THY C 1 107.024 37.166 -5.449 1.00 0.00 N1 C ATOM 10 O2 THY C 1 107.071 36.398 -6.397 1.00 0.00 N1 O ATOM 11 N3 THY C 1 106.027 37.104 -4.506 1.00 0.00 N1 N =cut __DATA__ ATOM 9 H5T THY C 1 107.274 35.359 -9.821 0.00 0.00 N1 H ATOM 10 O5' THY C 1 107.686 36.230 -9.553 1.00 0.00 N1 O ATOM 11 C5' THY C 1 108.813 35.973 -8.710 1.00 0.00 N1 C ATOM 12 H5' THY C 1 109.513 35.493 -9.239 0.00 0.00 N1 H ATOM 13 H5'' THY C 1 108.495 35.550 -7.861 0.00 0.00 N1 H ATOM 14 N1 THY C 1 107.956 38.157 -5.232 1.00 0.00 N1 N ATOM 15 C6 THY C 1 107.862 39.006 -4.149 1.00 0.00 N1 C ATOM 16 H6 THY C 1 108.479 39.755 -3.910 0.00 0.00 N1 H ATOM 17 C2 THY C 1 107.024 37.166 -5.449 1.00 0.00 N1 C ATOM 18 O2 THY C 1 107.071 36.398 -6.397 1.00 0.00 N1 O ATOM 19 N3 THY C 1 106.027 37.104 -4.506 1.00 0.00 N1 N

In reply to Re: renumber entries in column? by Marshall
in thread renumber entries in column? by aria

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.