If you have a string "one two three", which shell command
would you use to extract the strings?

Answer Posted / narendrasairam

Though cut command works, if the string is too long you cant
expect redundancy in the code. So, better to translate the
spaces first and then reading the lines.

echo "enter the string :"
read string

echo $string | tr " " "\n" | sed '/^$/d' > lines.out

while read line
do
echo $line
done < lines.out

Is This Answer Correct ?    3 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Devise a script that takes file name as arguement(which must present in the current directory)and locates from your home directory tree all thpath names of its links.Then mail the list to self.

1709


What is the first line in a shell script?

557


Explain about the exit command?

570


What is shell and shell script?

558


What is a shell made of?

558






What is meant by $1 in shell script?

549


Explain about login shell?

636


What is the syntax of "nested if statement" in shell scripting?

631


What does it mean to debug a script?

573


What is ms powershell?

583


What is difference between shell and bash scripting?

549


Print the 10th line without using tail and head command.

1674


What is the significance of the shebang line in shell scripting?

531


Explain about debugging?

606


How do you find out What is your shell?

592