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

How do I run a shell script in powershell?

628


Please give me example of " at command , contrab command " how to use

2419


How can any user find out all information about a specific user like his default shell, real-life name, default directory, when and how long he has been using the system?

794


How to check if the previous command was run successfully?

665


What makes c shell a more preferable option than the bourne shell?

624






How to find all the files modified in less than 3 days and save the record in a text file?

709


What is the significance of $#?

676


What is a beat in a script?

632


How to write a function?

676


how will you find the total disk space used by a specific user?

653


what is tickets $ what low,medium,high priorite pls define time also

1804


What does echo $0 do?

655


What is awk in shell scripting?

658


How to open a read-only file in the shell?

720


What is the conditional statement in shell scripting?

742