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.
I am betting there is a simple awk one liner that will do what I need. However, I haven't found it yet.
What I need is very simple. I want to take a mult-line input and convert to columns for each nth line.
Example: say n is 3 and the input is;
Quote:
some - text
more - text
even - more
yet - again
for - ever
stop - now
What I want returned is;
Quote:
some - text yet - again
more - text for - ever
even - more stop - now
Nothing more complicated than that. No special cases. Just convert n number of lines into columns with each column seperated by a space.
I guess there is one additional complication; In the example above if the number of lines on the input were 9 instead of 6 I would get 3 columns returned instead of two.
It is OK if the n is hard coded. As a matter of fact it's preferable.
I'm still digging so if I find a solution I will be sure to post it.
Distribution: openSUSE, Raspbian, Slackware. Previous: MacOS, Red Hat, Coherent, Consensys SVR4.2, Tru64, Solaris
Posts: 2,800
Rep:
Quote:
Originally Posted by syg00
Luv it - how to make awk look like perl ....
IMHO, only bonkers Perl programmers write code like that.
(I'm working on a project that uses a large number of Perl modules -- surely totaling well over 10,000 lines of code -- and none of what I've seen of the code base looks like that.)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.