How to get the last word from a line in Unix file?



How to get the last word from a line in Unix file?..

Answer / Abhinay Kandrap Kumar

You can use a combination of `cut`, `tr` and `wc` commands to get the last word from a line. The basic idea is to count spaces (or any delimiter) up to the second-last space, 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) - 1))` will give you the last word.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Unix General Interview Questions

What is architecture of unix operating system?

1 Answers  


How do you sort in unix?

1 Answers  


What is .profile unix?

1 Answers  


What is unix inode?

1 Answers  


unix command how to dispaly no of records in oracle?

5 Answers   SDF, TCS,


How to create a blank file in unix?

1 Answers  


Explain the following statement, “it is not advisable to use root as the default login.”

1 Answers  


What is $# in unix?

1 Answers  


What does shebang mean in unix?

1 Answers  


What are hidden files in unix?

1 Answers  


What are the three major components of any unix system?

1 Answers  


Is windows built on unix?

1 Answers  


Categories