In Bash, I want to get the Nth word of a string hold by a variable.
For instance:
STRING="one two three four" N=3
Result:
"three"
What Bash command/script could do this?
ToString(); var secondWord = tbt. Substring(indexnumber, tbt. IndexOf(" ")); var indexword2 = tbt. IndexOf(" ", indexnumber); var indexnumber2 = indexword2 + 1; string myString2 = indexnumber2.
(1) Select Text from the Formula type drop-down list; (2) Click to highlight Extract the nth word in cell in the Choose a formula list box; (3) In the Cell box, specify the cell that you will extract word from; (4) In The Nth box, specify the number.
echo $STRING | cut -d " " -f $N
An alternative
N=3 STRING="one two three four" arr=($STRING) echo ${arr[N-1]}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With