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 wc in shell script?

557


How to print the first array element?

550


Why is shell scripting important?

570


Write the syntax for "if" conditionals in linux?

591


What does chmod do?

570






How to get script name inside a script?

545


Differentiate between ‘ and ” quotes.

611


What are the different commands available to check the disk usage?

489


What are the two files of crontab command?

652


Write down the syntax of "for " loop

607


Shifting positional parameter in Linux fedora core ? Hi I have written following shell script for display value of positional. But in 11th and 12 field will display without shifting command. May I know is it advance of Linux of programming code error? #!/usr/bin/bash echo "Bellow is the out of ps command" echo "`ps`" echo "The passing Parameter i.e output of \$1,2... value is:==> $11 " echo "Total number of passed argument \$# is:==> $#" echo "Passed argument names (\$*) are:==>$*" echo "This script PID(\$$) is :=>$$" echo "The name of executing script(\$0) is :==>$0" echo "The Parent ID of this script(\$PPID) is:==>$PPID" And my input to this script is ./scriptname arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 arg11 arg12 Output Is Bellow is the out of ps command PID TTY TIME CMD 2892 pts/0 00:00:00 bash 3172 pts/0 00:00:00 positional_para 3173 pts/0 00:00:00 ps The passing Parameter i.e output of $1,2... value is:==> arg11 Total number of passed argument $# is:==> 13 Passed argument names ($*) are:==>arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9 arg10 arg11 arg12 arg13 This script PID($$) is :=>3172 The name of executing script($0) is :==>./positional_parameter The Parent ID of this script($PPID) is:==>2892 After the ps output please see the next line I.e $11 value comes out without shifting the parameter. How is it give me my friends

1752


What is the difference between scripting and coding?

535


Is shell and terminal the same?

591


What is the best shell scripting language?

537


In my bash shell I want my prompt to be of format '$"present working directory":"hostname"> and load a file containing a list of user-defined functions as soon as I log in, how will you automate this?

636