开发者

Split string by newline and space in Bourne shell

开发者 https://www.devze.com 2023-01-01 11:44 出处:网络
I\'m c开发者_开发百科urrently using the following to split a file into words - Is there some quicker way?

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

精彩评论

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

关注公众号