transpose every n lines into a single line transpose every n lines into a single line shell shell

transpose every n lines into a single line


Through awk.

$ awk -v RS= '{gsub(/\n/, " ")}1' filehi hello how are you i am fine how are youhi how is she doing i  have not  herd  from her


Treating blocks of text separated by blank lines as a single record is known as paragraph mode in awk:

$ awk -v RS= '{$1=$1}1' filehi hello how are you i am fine how are youhi how is she doing i have not herd from her


You can do this way too (a bit long though):

#!/bin/bashc=0while read -r idoif [[ $i == "" ]]; thenline="$line""\n"c=2elif [[ $c == "2" || $c == "0" ]]; thenline="$line""$i"c=1elseline="$line"" ""$i"fidone <file1echo -e "$line"

Ouptput:

hi hello how are you i am fine how are youhi how is she doing i have not herd from her