Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
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.
It contains
ABC A 123
ABC A 456
ABC A 789
HET A 123
HET A 123
HET A 567
ABC A 123
ABC A 565
ABC A 123
TER
ABC B 123
ABC B 456
ABC B 789
HET B 123
HET B 123
HET B 567
ABC B 123
ABC B 565
ABC B 123
TER
HET 123
HET 123
HET 678
Is there a way for linux to print all the lines between ABC A and TER(Lines 1-10) ?
The file is dynaminc, some files might have a 100 lines and some might have just 5. so head -n 5 doesnt work. Let me know if you know some command.
The -n turns of normal printing of lines,
'1,10p' prints (p) lines 1 to 10 (or up to as many as ten).
Hope this helps.
The thing is I dont know the line numbers. All i know is the First 6 characters of my string are "ABC A" and the script should stop read when it hits TER
Maybe this will help. It's the same command, but using regexp to determine the line numbers:
sed -n '/ABC A/,/TER/p' infile
If the input given in your first post is used, the following is the output:
ABC A 123
ABC A 456
ABC A 789
HET A 123
HET A 123
HET A 567
ABC A 123
ABC A 565
ABC A 123
TER
Hope this works for you.
Thanks a lot! You helped me out a lot!
One small question.
is it possible to make sed read the lines only if its starts with ABC?
like sed -n ^'/ABC A/,/TER/p' infile
that doesnt work... what do i do?
If this is from the same example you were using yesterday, here is another way using sed.
Code:
sed -n '/.*A/{N;/HET/!p}' file.txt
Its from the same example... but bit modified
Here the textfile
Quote:
ATOM 6 CG PHE A 10 41.541 39.112 129.318 1.00 17.02 1LYN 122
ATOM 7 CD1 PHE A 10 40.620 38.062 129.219 1.00 14.04 1LYN 123
ATOM 8 CD2 PHE A 10 42.614 39.064 130.228 1.00 13.11 1LYN 124
ATOM 9 CE1 PHE A 10 40.803 36.968 130.050 1.00 17.76 1LYN 125
HETATM 10 CE2 PHE A 10 42.775 37.957 131.042 1.00 13.57 1LYN 126
HETATM 11 CZ PHE A 10 41.863 36.927 130.940 1.00 14.80 1LYN 127
HETATM 12 N LEU A 11 39.446 39.166 125.736 1.00 9.66 1LYN 128
ATOM 13 CA LEU A 11 38.377 39.739 124.894 1.00 6.95 1LYN 129
ATOM 14 C LEU A 11 36.961 39.283 125.285 1.00 8.02 1LYN 130
ATOM 15 O LEU A 11 36.756 38.173 125.782 1.00 13.20 1LYN 131
ATOM 16 CB LEU A 11 38.751 39.340 123.479 1.00 4.67 1LYN 132
ATOM 17 CG LEU A 11 38.383 40.028 122.209 1.00 6.25 1LYN 133
ATOM 18 CD1 LEU A 11 38.872 39.094 121.148 1.00 13.72 1LYN 134
ATOM 19 CD2 LEU A 11 36.926 40.178 121.929 1.00 10.47 1LYN 135
ATOM 20 N ASN A 12 35.919 40.058 125.133 1.00 7.45 1LYN 136
ATOM 21 CA ASN A 12 34.571 39.734 125.566 1.00 5.18 1LYN 137
TER
So it must start reading ".....................A" and end at TER.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.