比如文件中有这样的字符串:
a.txt
rei9aiwe bohth4zu go3eimum ichiesh5iveesh2j eiziv0bo lu2efooz feey5ohr
要转换成下面的形势:
b.txt
rei9aiwebohth4zugo3eimumichiesh5iveesh2jeiziv0bolu2efoozfeey5ohr
如何做?
语言不限,php/ruby/python都可以。
回复内容: 比如文件中有这样的字符串:
a.txt
rei9aiwe bohth4zu go3eimum ichiesh5iveesh2j eiziv0bo lu2efooz feey5ohr
要转换成下面的形势:
b.txt
rei9aiwebohth4zugo3eimumichiesh5iveesh2jeiziv0bolu2efoozfeey5ohr
如何做?
语言不限,php/ruby/python都可以。
sed 's/\s\+/\n/g' a.txt > b.txt
或者
tr ' ' '\n' b.txt
或者用 python:
python -c 'open(b.txt, w).write(open(a.txt).read().replace( , \n))'
这样的任务,超过一行的代码就实在是太浪费啦。
既然语言不限,来一个另类的,目测没几个知道是什么语言
import[a.txt]~stringreplace~( -> \n) // export[b.txt, #] &
补充个ruby 版
open(b.txt, w).puts open('a.txt').read.gsub , \n
python
myfile = open(a.txt)temp = for line in myfile.readlines(): for a in line.split(): temp += a + '\n'myfile.close()file_object = open('b.txt', 'w')file_object.writelines(temp)file_object.close()