I am trying to transpose a content of a file into another. I am new to shell scripting any help would be really appreciated Input file Test.txt:HLRSN = 3IMSI = 404212109727229KIVALUE = A24AD11812232B47688ADBF15CE05CA9K4SNO = 1CARDTYPE = SIMALG = COMP128_3HLRSN = 3IMSI = 404212109727230KIVALUE = A24AD11812232B47688ADBF15CE05CB8K4SNO = 1CARDTYPE = SIMALG = COMP128_3HLRSN = 3IMSI = 404212109727231KIVALUE = A24AD11812232B47688ADBF15CE05CD6K4SNO = 1CARDTYPE = SIMALG = COMP128_3Output needed in annother text file:3,404212109727229,A24AD11812232B47688ADBF15CE05CA9,1,SIM,COMP128_33,404212109727230,A24AD11812232B47688ADBF15CE05CB8,1,SIM,COMP128_33,404212109727231,A24AD11812232B47688ADBF15CE05CD6,1,SIM,COMP128_3
Convert key=value blocks to CSV
shell;text processing;csv
A bash solution:declare -a outEOF=falseIFS=$'='until $EOF; do  read -r skip val || EOF=true  if [ ! -z $val ]  then    out+=(${val//[[:space:]]/})  else    tmp=${out[@]}    printf '%s\n' ${tmp// /,}    out=()  fidone < fileHow does this workDeclare array out for holding output line, set variable EOF to keep track end of file, IFS for input field separator for read.Until we read end of file, we read each line of file, set value of last field to variable val.if [ ! -z $val ]: check if length of variable $val is not zero, we remove space in $val, push it to array out.if length $val is zero, meaning we get blank line or end of file, we assign all element of array out to variable tmp, then replace all space variable tmp by ,, our designed output recode separator.Set out to null for next work.Another solution, more concise, shorter for you is using perl:$ perl -F'=' -anle '    BEGIN { $, = , }    push @out,$F[-1] if @F;    print @{[map {s/\s// && $_} @out]} and @out = ()        if /^$/ or eof;' file3,404212109727229,A24AD11812232B47688ADBF15CE05CA9,1,SIM,COMP128_33,404212109727230,A24AD11812232B47688ADBF15CE05CB8,1,SIM,COMP128_33,404212109727231,A24AD11812232B47688ADBF15CE05CD6,1,SIM,COMP128_3