0

I have a CSV file. The contents are as follows:

1, 10, 10, 10, 11, 100, 10, 101, 100, 10, 110, 90, 111

Is there a Linux command to take each comma, delete it, and put a newline on the end? So it looks more like this:

1 
10 
10
10
11 
100 
10
101
100
10
110
90
111

Help is appreciated! Thanks!

  • Does this answer your question? [Replace comma with newline in sed on MacOS?](https://stackoverflow.com/questions/10748453/replace-comma-with-newline-in-sed-on-macos) – Alex Apr 30 '21 at 22:52
  • @Alex No, thank you though. I am running Debian 10 Linux (Beta) on an HP Chromebook G14. – Ryan Ilari May 02 '21 at 17:49
  • Debian also has `sed`. The link also has a solution using `try tr , '\n'`. – Alex May 02 '21 at 20:35

3 Answers3

0

Open the file in Vim, hit Esc, type :%s/,/\r/g, and hit Enter. This will replace all the commas in the file with new lines.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
0

With awk:

$ awk -F', ' 'BEGIN{OFS="\n"}{$1=$1}1' file

With sed:

$ sed 's/, /\n/g' file

Output:

1
10
10
10
11
100
10
101
100
10
110
90
111
Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223
0
 echo '1, 10, 10, 10, 11, 100, 10, 101, 100, 10, 110, 90, 111' | 

mawk $$ RS='[\7--]+' 

1
10
10
10
11
100
10
101
100
10
110
90
111

you can even make them tier only when ever encountering more digits :


gawk NF=NF OFS='\f\t\b\b\b\b'

1,
    10, 
    10, 
    10, 
    11, 
    100,
            10, 
            101,
                    100,
                            10, 
                            110,
                                    90, 
                                    111 
RARE Kpop Manifesto
  • 2,453
  • 3
  • 11