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.
... works for the 5-word example but I don't know how to generalize it for lines of any length.
A data snippet to play with...
Quote:
000001 once upon a midnight dreary while i pondered weak and weary
000002 over many a quaint and curious volume of forgotten lore
000003 while i nodded nearly napping suddenly there came a tapping
000004 as of some one gently rapping rapping at my chamber door
000005 tis some visitor i muttered tapping at my chamber door
000006 only this and nothing more
$ sed -r 's/ +/\n/g; :a; s/\n/ /; s/(([0-9]+) [^\n]*)\n/\1 \2\n/; ta;' infile.txt
000001 once 000001 upon 000001 a 000001 midnight 000001 dreary 000001 while 000001 i 000001 pondered 000001 weak 000001 and 000001 weary
000002 over 000002 many 000002 a 000002 quaint 000002 and 000002 curious 000002 volume 000002 of 000002 forgotten 000002 lore
000003 while 000003 i 000003 nodded 000003 nearly 000003 napping 000003 suddenly 000003 there 000003 came 000003 a 000003 tapping
000004 as 000004 of 000004 some 000004 one 000004 gently 000004 rapping 000004 rapping 000004 at 000004 my 000004 chamber 000004 door
000005 tis 000005 some 000005 visitor 000005 i 000005 muttered 000005 tapping 000005 at 000005 my 000005 chamber 000005 door
000006 only 000006 this 000006 and 000006 nothing 000006 more
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.