How to convert a comma delimited string to records or lines of text?

Hi,

I am not sure if I've posted this question before.

Anyway, I previously asked about converting lines of text into a comma delimited string. Now I am needing to do the other way around ... :frowning: :o

Can anyone advise how is this possible?

Example as below:

Converting records/lines to a single delimited string


$ cat /tmp/x.txt
user1
user2
user3
user4
$ cat /tmp/x.txt | awk 'NR == 1 {printf "%s", $0; next} {printf ",%s", $0} END {print ""}'
user1,user2,user3,user4

$

Now I need to read a comma delimited string and convert it into records. So reading the string

user1,user2,user3,user4

And making it into something like below sorted accordingly.

user1
user2
user3
user4

I then compare this with another list of records and check for differences :frowning:

Advise much appreciated. Thanks in advance.

Hello newbie_01,

Following may help you in same.

awk -F"," '{for(i=1;i<=NF;i++){print $i}}' Input_file
OR
awk '{gsub(/\,/,"\n",$0);print $0}' Input_file

Thanks,
R. Singh

Did you even consider searching in here for solutions to this very common request? Try

tr ',' '\n' < file3
user1
user2
user3
user4