How to extract the second word from a string in Bash

2 Answers

0 votes
S="bash python java c c++ c#"

echo $S | cut -d " " -f 2



    
    
# run:
#
# python
#

 



answered May 27, 2021 by avibootz
0 votes
S="bash python java c c++ c#"

second_word=$(echo $S | awk '{print $2}')
echo $second_word



    
    
# run:
#
# python
#

 



answered May 27, 2021 by avibootz

Related questions

2 answers 568 views
1 answer 246 views
1 answer 246 views
1 answer 233 views
233 views asked May 28, 2021 by avibootz
1 answer 230 views
2 answers 282 views
1 answer 244 views
...