Issue
I have a file say test.txt, which contains data as a list of values/strings and also has some empty lines in between as shown below
Val1
Val2
Val3
Val4
Val5
Val6
Required output:
Val1, Val2, Val3
Val4, Val5
Val6
I am using the below command, but it's returning all the available values in a single line. But I want only consecutive values to be concatenated together(comma separated) and a new line should start whenever it hits an empty line (there can be more than one consecutive empty line).
cat test.txt | sed 's/<[^>]*>//g' | sed 's/ //g' | sed 's/.*/&/;$!s/$/, /' | tr -d '\n'
Solution
I think this is what you're trying to do, using any awk:
$ awk -v RS= -F'\n' -v OFS=', ' '{$1=$1} 1' test.txt
Val1, Val2, Val3
Val4, Val5
Val6
Answered By - Ed Morton Answer Checked By - Cary Denson (WPSolving Admin)