LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   command to print the last field (https://www.linuxquestions.org/questions/linux-software-2/command-to-print-the-last-field-853011/)

dsids 12-29-2010 07:34 AM

command to print the last field
 
Hi,

Is there a way to extract the last field?

Specifying the field number is causing problems using awk or cut as the input log file has the output specified in different lines at different places/fields. The only thing constant is the 'pathname' which always occurs at the end, which is what I want

Thanks a lot

D

druuna 12-29-2010 07:43 AM

Hi,

Is this what you are looking for: awk '{ print $NF }' infile

NF is special in awk, it tells you how many fields there are, using it as $NF will print the last field.

Hope this helps.

dsids 12-29-2010 08:17 AM

Quote:

Originally Posted by druuna (Post 4206529)
Hi,

Is this what you are looking for: awk '{ print $NF }' infile

NF is special in awk, it tells you how many fields there are, using it as $NF will print the last field.

Hope this helps.


Thanks a lot...it helps

druuna 12-29-2010 09:03 AM

You're welcome :)

If this is issue is fixed, could you put up the solved flag (First post -> Thread Tools)?


All times are GMT -5. The time now is 04:08 PM.