0

Can you help me out to bring string of array which is in one text file say

Apple banana mango grapes 

I should be get like each word in different line

Apple 
Banana 
Mango
Grape 

and store in another text file using bash she'll

1
  • Please update the question with some sample code with what you've tried, and a clear explanation of the problem. Commented Sep 29, 2015 at 16:25

4 Answers 4

1

You can use grep -o

grep -Eo '\w+' file
Apple
banana
mango
grapes
Sign up to request clarification or add additional context in comments.

Comments

1

use tr

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

or sourced from file

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

Comments

1

With pure Bash:

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

The set -o noglob is necessary to prevent pathname expansion (globbing) after $(< file) is expanded.

Comments

0

You can use cat stack.txt | tr ' ' '\n' >outfile.txt

or just cat stack.txt | tr ' ' '\n' for outputting on the terminal

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.