You could use awk to split each block into separate files, then paste them together (below is assuming always there is empty lines between each lists).
awk '/^$/ {N++;next}{print >"file"N}' infile.txt
paste file*
Also you can move the paste command into awk.
awk '/^$/ {N++;next}{print >"file"N} END{system("paste file*")}' inile.txt
The output is:
List A List B List C
hi Hi Hello
hello Yes
hw r u
to having beauty indentation in result when varying lines length like below:
Input file:
list A
hi
hello
hw r u
List B
Hi this is list B
Yes
List C
Hello, this is list C
you can do paste file* |column -s $'\t' -tn and will have result:
list A List B List C
hi Hi this is list B Hello, this is list C
hello Yes
hw r u
awk,csplitmight be more suitable as it is designed for file splitting on a pattern match. In this case match empty lines and delete the match pattern:csplit -f file_ --suppress-matched infile.txt '/^$/' '{*}'. ALSO: Note that the pasting viapaste file*might be problematic when havingfile1andfile10. – FelixJN Sep 18 '20 at 08:17