0

What are some simple options to split a single text line into separate based on a character or pattern? I would like to do this from the command line.

An example would be when you want to inspect the PATH. With a single simple command I'd like to split something like:

    /Users/jeff/.rvm/gems/ruby-2.2.1/bin:/Users/jeff/.rvm/gems/ruby-2.2.1@global/bin:/Users/jeff/.rvm/rubies/ruby-2.2.1/bin:/opt/local/bin:/opt/local/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/texbin:/Users/jeff/bin:/Users/jeff/Utveckling/Alan/alan/bin:/Users/jeff/.gem/ruby/1.8/bin:/Users/jeff/.rvm/bin

into the much more readable

/Users/jeff/.rvm/gems/ruby-2.2.1/bin
/Users/jeff/.rvm/gems/ruby-2.2.1@global/bin
/Users/jeff/.rvm/rubies/ruby-2.2.1/bin
/opt/local/bin
/opt/local/sbin
/opt/local/bin
/opt/local/sbin
/usr/local/mysql/bin
/opt/local/bin
/opt/local/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
/opt/X11/bin
/usr/texbin
/Users/jeff/bin
/Users/jeff/Utveckling/Alan/alan/bin
/Users/jeff/.gem/ruby/1.8/bin:/Users/jeff/.rvm/bin
thoni56
  • 3,145
  • 3
  • 31
  • 49

2 Answers2

0

Something like

sed s/:/\\n/g yourinput

should do the trick

StephaneM
  • 4,779
  • 1
  • 16
  • 33
0

Using tr actually was easier, as show in e.g. this question. Here's the command

echo $PATH | tr ':' '\n'
Community
  • 1
  • 1
thoni56
  • 3,145
  • 3
  • 31
  • 49