I have the following text file.
# This is a test 1
"watch"
"autoconf"
# This is another line 2
"coreutils"
"binutils"
"screen"
# This is another line 3
"bash"
"emacs"
"nano"
"bison"
# This is another line 4
"libressl"
"python"
"rsync"
"unzip"
"vim"
I want to change this to the following:
# This is a test 1
watch, autoconf
# This is another line 2
coreutils, binutils, screen
# This is another line 3
bash, emacs, nano, bison
# This is another line 4
libressl, python, rsync, unzip, vim
Remove the leading white spaces, remove quotes, replace a new line with a comma.
So far I got this:
$ cat in.txt | sed 's/"//g' | sed 's/^[[:space:]]*//'> out.txt
# This is a test 1
watch
autoconf
# This is another line 2
coreutils
binutils
screen
# This is another line 3
bash
emacs
nano
bison
...
I'm not sure how to replace a new line with a comma. I tried the following.
# no change
$ cat in.txt | sed 's/"//g' | sed 's/^[[:space:]]*//'| sed 's/\n/,/g'> out.txt
# changed all new lines
$ cat in.txt | sed 's/"//g' | sed 's/^[[:space:]]*//'| sed -z 's/\n/,/g'> out.txt
$ cat out.txt
# This is a test 1,watch,autoconf,,# This is another line 2,coreutils,binutils,screen,,# This is another line 3,bash,emacs,nano,bison,,# This is another line 4,libressl,python,rsync,unzip,vim
How can I achieve this?