Posted: . At: 9:16 AM. This was 4 years ago. Post ID: 14565
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.


Convert text from comma delimited to newline delimited with a simple command.


Some text files are shipped as comma-delimited files. This can be annoying to fix, but it can be done with the Linux command line.

Here is an example of comma-delimited text.

jason@jason-desktop:~/Documents$ cat banlist.txt | head -c 200 ; echo
10.34.28.4, 103.11.70.143, 103.11.70.143, 103.22.245.6, 107.20.178.108, 108.163.248.74, 108.21.102.146, 108.62.110.25, 108.62.33.114, 108.62.33.114, 108.62.62.164, 109.162.20.227, 109.162.20.28, 109.1

Then I use sed to convert it to newline delimited with a simple command.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
jason@jason-desktop:~/Documents$ sed s'/, /\n/gi' banlist.txt | head -n 20
10.34.28.4
103.11.70.143
103.11.70.143
103.22.245.6
107.20.178.108
108.163.248.74
108.21.102.146
108.62.110.25
108.62.33.114
108.62.33.114
108.62.62.164
109.162.20.227
109.162.20.28
109.162.21.233
109.162.53.96
109.162.53.96
109.162.64.177
109.173.21.1
109.173.69.155
109.195.171.53

That is how easy it is to convert a file from comma-delimited to a newline delimited format with one simple command.

This is how to do it.

jason@jason-desktop:~/Documents$ sed s'/, /\n/gi' banlist.txt > banlistnew.txt

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.