根据字符或模式将单个文本行拆分为多个简单选项有哪些?我想从命令行执行此操作。
一个例子就是你想要检查PATH。只需一个简单的命令,我就可以分开:
/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
更可读
/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
答案 0 :(得分:0)
像
这样的东西sed s/:/\\n/g yourinput
应该做的伎俩
答案 1 :(得分:0)
使用 tr 实际上更容易,例如在this问题。这是命令
echo $PATH | tr ':' '\n'