adspace
Answer Posted / Ashish Mani Tiwari
In Unix, you can use a combination of `cut` and `tr` commands to extract the nth word from a given line. The basic idea is to count spaces (or any delimiter) up to `n-1`, then print the rest until the end of the line. Here's an example: `echo "This is a test" | cut -d" " -f$(($(echo "This is a test" | tr " "
| wc -l) - 2))` will give you the last word.
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers