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

**URL:** <https://community.unix.com/t/how-to-convert-a-comma-delimited-string-to-records-or-lines-of-text/347807>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [November 5, 2014, 1:25am UTC](https://community.unix.com/t/how-to-convert-a-comma-delimited-string-to-records-or-lines-of-text/347807 "2014-11-05T01:25:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![newbie\_01](https://community.unix.com/letter_avatar/newbie_01/32/5_5575768a8748004e209b776fc1b2916d.png) [@newbie\_01](https://community.unix.com/u/newbie_01)\
**Post date:** [November 5, 2014, 1:25am UTC](https://community.unix.com/t/how-to-convert-a-comma-delimited-string-to-records-or-lines-of-text/347807/1 "2014-11-05T01:25:38Z")

</div>

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 ... ☹ :o

Can anyone advise how is this possible?

Example as below:

Converting records/lines to a single delimited string

```nohighlight

$ 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

```nohighlight
user1,user2,user3,user4

```

And making it into something like below sorted accordingly.

```nohighlight
user1
user2
user3
user4

```

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

Advise much appreciated. Thanks in advance.

---

<div class="post-metadata">

**Author:** ![RavinderSingh13](https://community.unix.com/letter_avatar/ravindersingh13/32/5_5575768a8748004e209b776fc1b2916d.png) [@RavinderSingh13](https://community.unix.com/u/RavinderSingh13)\
**Post date:** [November 5, 2014, 1:32am UTC](https://community.unix.com/t/how-to-convert-a-comma-delimited-string-to-records-or-lines-of-text/347807/2 "2014-11-05T01:32:03Z")

</div>

Hello newbie\_01,

Following may help you in same.

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

```

Thanks,  
R. Singh

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [November 5, 2014, 4:32am UTC](https://community.unix.com/t/how-to-convert-a-comma-delimited-string-to-records-or-lines-of-text/347807/3 "2014-11-05T04:32:10Z")

</div>

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

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

```
