Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
With GNUUsing any awk for multi-char RS and \s:
\s
$ awk -v RS='\\s+' '{ORS=printf "%s%s", $0, (NR%2NR%3 ? OFS : "\n"ORS)} 1'' file ABC 1223334 Days 344678544324677 Base 45666 ABC 1234565 Days 234567899765443 Base 456643
With GNU awk for multi-char RS and \s:
$ awk -v RS='\\s+' '{ORS=(NR%2 ? OFS : "\n")} 1' file ABC 1223334 Days 344678544324677 Base 45666 ABC 1234565 Days 234567899765443 Base 456643
Using any awk:
$ awk '{printf "%s%s", $0, (NR%3 ? OFS : ORS)}' file ABC 1223334 Days 344678544324677 Base 45666 ABC 1234565 Days 234567899765443 Base 456643
$ awk -v RS='\\s+' 'NR%2'{s=$0;ORS=(NR%2 next}? {printOFS s,: $0"\n")}' 1' file ABC 1223334 Days 344678544324677 Base 45666
or with any awk and tr:
$ tr ' ' '\n' < file | awk 'NR%2{s=$0; next} {print s, $0}' ABC 12233341234565 Days 344678544324677234567899765443 Base 45666456643
$ awk -v RS='\\s+' 'NR%2{s=$0; next} {print s, $0}' file ABC 1223334 Days 344678544324677 Base 45666
$ tr ' ' '\n' < file | awk 'NR%2{s=$0; next} {print s, $0}' ABC 1223334 Days 344678544324677 Base 45666
$ tr ' ' $'\n''\n' < file | awk 'NR%2{s=$0; next} {print s, $0}' ABC 1223334 Days 344678544324677 Base 45666
$ tr ' ' $'\n' < file | awk 'NR%2{s=$0; next} {print s, $0}' ABC 1223334 Days 344678544324677 Base 45666