Replacing selected columns by Serial numbers incremently
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Replacing selected columns by Serial numbers incremently
Hi all,
I have a file like this:
ATOM 2 CA GLU A 76 -1.924 17.878 -5.440 1.00 51.41
ATOM 11 CA PRO A 77 -2.544 20.862 -2.979 1.00 37.40
ATOM 18 CA GLU A 78 -6.174 21.593 -2.142 1.00 30.40
ATOM 27 CA TRP A 79 -7.750 24.746 -3.511 1.00 17.67
TER
ATOM 2 CA THR G 1 28.430 63.361 51.737 1.00 42.22
ATOM 9 CA PRO G 2 26.967 63.584 55.274 1.00 31.31
ATOM 16 CA GLN G 3 29.684 62.824 57.805 1.00 33.82
ATOM 25 CA ASN G 4 27.515 61.696 60.704 1.00 26.00
ATOM 33 CA ILE G 5 24.191 60.162 61.569 1.00 20.73
ATOM 41 CA THR G 6 22.747 63.483 62.717 1.00 25.06
ATOM 48 CA ASP G 7 23.391 65.211 59.400 1.00 28.96
ATOM 56 CA LEU G 8 22.227 62.164 57.477 1.00 25.58
ATOM 64 CA CYS G 9 19.067 61.936 59.557 1.00 22.32
ATOM 70 CA ALA G 10 18.422 65.589 58.785 1.00 27.72
ATOM 75 CA GLU G 11 18.011 64.885 55.069 1.00 26.90
ATOM 84 CA TYR G 12 14.628 63.226 55.416 1.00 26.27
TER
ATOM 2 CA LYS A 865 50.023 37.415 38.084 1.00102.35
ATOM 11 CA ASN A 866 47.964 34.458 39.220 1.00 99.96
ATOM 19 CA LEU A 867 48.644 30.875 40.293 1.00 96.60
ATOM 27 CA ASP A 868 49.443 28.917 37.158 1.00 92.43
TER
I want the 2nd field i.e field having numbers 2, 11, 18, 27 so on to be replaced by 1, 2, 3 incremently til the last line of the file but excluding those lines having TER. I mean starting with the 1st line i.e ATOM 2, it shoud start with replacing the 2nd fields by Sl. numb incremently excluding those lines having TER in them.
Similarly, i wan the 6th field, i.e again number column to start with one and increments til TER is found......TER refrers to termination of that substance.....so next, again the field shoud increment, for eg. in the 3rd substance the line starts with
ATOM 2 CA LYS A 865 50.023 37.415 38.084 1.00102.35....
Here 865 shud b relaced by one and shud increment in the same field/column til TER comes.......
Please help me........i am in great need for this......
I am using a different approach, but its not yielding me the perfect o/p..
i am using cut, grep and loops for the particular fields by using pipes.....but wat i wan s for 2 of my fields and also numbering not for TER line.....so.........
What's wrong with the awk approach? It's almost certainly faster than a combination of a loop in shell script with cuts, greps and so on all over the place.
Hi matthew....
The awk code that u gave is incrementing the 2nd field in the same way of the 6th field.....
I want the 2nd field to be incremented from 1 to the last line (1 to 34689 in my file) excluding the TER line.....i mean it shoud not count the line having "TER"....
The code is doing good with the 6th field. i.e incrementing til TER and again beginning with 1 till TER is found, but this is not what i wanted in the 2nd field...
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.