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

What is eval in shell script?

910


Using set -A write a script to print the output of the ls command in 5 columns with two spaces between each column. Pretend that ls does not have multicolumn output.

2412


What is an sh file?

749


How can you get the value of pi till a 100 decimal places?

761


Differentiate between ‘ and ” quotes.

818


What is $1 in shell scripting?

811


What are the 3 standard streams in linux?

781


What does egrep mean?

756


How will you print the login names of all users on a system?

753


What can you do with powershell?

830


What are the different types of variables used in shell script?

764


How will you pass and access arguments to a script in linux?

809


c program the catches the ctrl-c(SIGINT) Signal for the first time and prints a output rather and exit on pressing Ctrl-C again

5945


What are the different variables present in linux shell?

807


How to print the first array element?

805