Skip to main content
Post Undeleted by Ed Morton
deleted 47 characters in body
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60

With GNUUsing any awk for multi-char RS and \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 
Post Deleted by Ed Morton
Post Undeleted by Ed Morton
deleted 96 characters in body
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60

With GNU awk for multi-char RS and \s:

$ 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 

With GNU awk for multi-char RS and \s:

$ awk -v RS='\\s+' 'NR%2{s=$0; next} {print s, $0}' 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 1223334 Days 344678544324677 Base 45666 

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 
Post Deleted by Ed Morton
`tr` understands `\n` as newline without C-string quoting.
Source Link
Kusalananda
  • 356.1k
  • 42
  • 737
  • 1.1k

With GNU awk for multi-char RS and \s:

$ awk -v RS='\\s+' 'NR%2{s=$0; next} {print s, $0}' file ABC 1223334 Days 344678544324677 Base 45666 

or with any awk and tr:

$ tr ' ' $'\n''\n' < file | awk 'NR%2{s=$0; next} {print s, $0}' ABC 1223334 Days 344678544324677 Base 45666 

With GNU awk for multi-char RS and \s:

$ awk -v RS='\\s+' 'NR%2{s=$0; next} {print s, $0}' 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 1223334 Days 344678544324677 Base 45666 

With GNU awk for multi-char RS and \s:

$ awk -v RS='\\s+' 'NR%2{s=$0; next} {print s, $0}' 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 1223334 Days 344678544324677 Base 45666 
Source Link
Ed Morton
  • 35.9k
  • 6
  • 25
  • 60
Loading