开发者

Split string by newline and space in Bourne shell

I'm c开发者_开发百科urrently using the following to split a file into words - Is there some quicker way?

while read -r line
do
    for word in $line
    do
        words="${words}\n${word}"
    done
done


What about using tr?

tr -s '[:space:]' '\n' < myfile.txt

The -s squeezes multiple whitespace characters into one.


xargs -n 1  echo <myfile.txt


sed 's/[[:space:]]/\n/g' file.txt
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜