GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Operating System  >  Shell Scripting
Go To First  |  Previous Question  |  Next Question 
 Shell Scripting  |  Question 9 of 47    Print  
If you have a string "one two three", Which shell command would you use to extract the strings?

  
Total Answers and Comments: 12 Last Update: August 24, 2009   
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: abhay
 
echo "one two three" | cut -d" " -f 1,2,3 
or 
echo "one two three" | awk '{print $1 $2 $3}' 


Above answer was rated as good by the following members:
balaksara
  Sorting Options  
  Page 1 of 2   « First    1    2    >     Last »  
June 06, 2005 07:25:16   #1  
Rishi Pahuja        

RE: If you have a string "one two three", Which shell command would you use to extract the strings?
echo $string | cut -d -f1
echo $string | cut -d -f2
echo $string | cut -d -f3



 
Is this answer useful? Yes | No
July 05, 2005 01:19:37   #2  
abhay        

RE: If you have a string "one two three", Which shell command would you use to extract the strings?
echo one two three | cut -d -f 1 2 3
or
echo one two three | awk '{print $1 $2 $3}'

 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
July 27, 2005 15:34:21   #3  
akebono        

RE: If you have a string "one two three", Which shell command would you use to extract the strings?
sed and awk

 
Is this answer useful? Yes | No
October 05, 2006 05:01:13   #4  
rno        

RE: If you have a string "one two three", which shell ...
cut awk sed and others are not SHELL commands. One way could be with bash: string one two three tab ($string)$ echo ${tab[0]}one$ echo ${tab[1]}two$ echo ${tab[2]}threehttp://www.big-up.org
 
Is this answer useful? Yes | No
March 20, 2007 11:50:53   #5  
atrain        

RE: If you have a string "one two three", Which shell ...
echo "one two three" | while read ONE TWO THREE
print $ONE
one
print $TWO
two
print $THREE
three

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    
April 04, 2007 11:44:15   #6  
pranab kumar ghosh        

RE: If you have a string "one two three", Which shell ...
set -- one two three
echo $1
echo $2
echo $3

 
Is this answer useful? Yes | No
April 13, 2007 07:20:40   #7  
Jitu        

RE: If you have a string "one two three", Which shell ...
Hi all

Can we use like this..

echo $string | tr " " "n"

Here the output will be something like this

One
Two
Three


if the value of string "One Two Three"

Please make me clear if i am wrong..i am a new baby to shell scripting. :-)
Thanks
Jitu

 
Is this answer useful? Yes | No
June 27, 2007 01:20:31   #8  
Vishwajeet        

RE: If you have a string "one two three", Which shell ...
Hi The answer is excellent but I like to modify it a little only the command
string one two three tab ($string)$ echo ${tab[0]}one ${tab[1]}two ${tab[2]}three it self is enough to ptint one two three no more echos' are required.

 
Is this answer useful? Yes | No
May 31, 2008 01:18:35   #9  
amangautam80 Member Since: May 2008   Contribution: 2    

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

input "one two three"
echo $input | tr " " "n"

output would be like :

one
two
three

one of my friend gave this answer but in place of "n" he gave "n" only which will gave
output like :

onentwonthree

thanks


 
Is this answer useful? Yes | No
May 31, 2008 01:21:13   #10  
amangautam80 Member Since: May 2008   Contribution: 2    

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

Sorry typo error... in place on n we have to give "n"


 
Is this answer useful? Yes | No
  Page 1 of 2   « First    1    2    >     Last »  


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape