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

Answer Posted / swaroopa

Below methods will work. You could use either cut or awk

echo "read data"
read data

echo $data | cut -f1 -d" "
echo $data | cut -f2 -d" "
echo $data | cut -f3 -d" "

echo $data |awk -F" " '{print $1}'
echo $data |awk -F" " '{print $2}'
echo $data |awk -F" " '{print $3}'

Is This Answer Correct ?    9 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I want to create a directory such that anyone in the group can create a file and access any person's file in it but none should be able to delete a file other than the one created by himself.

597


What language is used in terminal?

558


What is an sh file?

559


Is shell scripting useful?

595


What happens when you type ls?

565






I want to monitor a continuously updating log file, what command can be used to most efficiently achieve this?

754


What are different types of shell?

493


Why should we use shell scripts?

592


What is echo $shell?

624


What is a file basename?

594


What can scripts do?

666


What is shell prompt?

563


Explain about the exit command?

570


How will you connect to a database server from linux?

557


Is shell script a programming language?

569