Concatenate column 1 and column 2 of related lines
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.
Concatenate column 1 and column 2 of related lines
Hi everyone,
I have a file containing many lines, some of them begin with 74521 in column 1, others have the word "ATRB" in column 5, an the rest other info that doesnt care to me.
I´ve filtered only lines containing what I´ve explained above using
Code:
awk '/74521/||/ATRB/' source.txt > output.txt
The filtering result is
Code:
74521019143 515097017017121 COMPLETE AVAILABLE
74521019149 515097017017161 COMPLETE AVAILABLE
74521956785 515097011027927 COMPLETE AVAILABLE
2 1 NO X-1 ATRB 1
3 5 NO X-1 ATRB 2
1 3 NO X-1 ATRB 3
74521956787 515097011027929 COMPLETE AVAILABLE
2 1 NO X-1 ATRB 1
3 2 NO X-1 ATRB 2
1 1 NO X-1 ATRB 3
74521900844 515097014501216 COMPLETE AVAILABLE
2 0 NO ATRB 1
1 0 NO ATRB 2
3 0 NO ATRB 3
5 1 NO ATRB 4
Every line containing "ATRB" after one particular line that begin with 74521
is part of that line. 2 consecutive lines that begin with "75421", may dont have
lines containing the word "ATRB" between them, in this case that lines
are not interesting either.
Based on this info and the filtered file I´ve got at the moment I´like to obtain
a last arrangement using colum 1 & column 2 of lines that begin with 74521 and the
correspondent column 1 & column 2 of lines that contain "ATRB". This four columns
in the same line as follow
Now, I only trying to include analysis of some other cases that could happen, I hope be succesful in that thask, but with the code you´ve gave me it´s almost 99% of what I needed.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.