2015-09-29 65 views
0

你能幫我把數組的字符串,它是在一個文本文件中說我怎樣才能把數組的字符串轉換成文件

Apple banana mango grapes 

我應該得到像在不同的行中的每個字

Apple 
Banana 
Mango 
Grape 

和使用bash在另一個文本文件存儲,她會

+0

請更新與你已經嘗試了一些什麼樣的代碼,以及問題的解釋清楚的問題。 – ergonaut

回答

1

您可以使用grep -o

grep -Eo '\w+' file 
Apple 
banana 
mango 
grapes 
1

使用tr

echo "Apple banana mango grapes" | tr -s ' ' '\n' > output 

或從文件

tr -s ' ' '\n' <file > output 
1

隨着純擊來源:

set -o noglob 
printf '%s\n' $(< file) 

set -o noglob需要防止路徑擴展(通配符)$(< file)後膨脹。

0

您可以使用cat stack.txt | tr ' ' '\n' >outfile.txt

或只是cat stack.txt | tr ' ' '\n'用於輸出終端

相關問題