LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   cut part of a string using awk (http://www.linuxquestions.org/questions/programming-9/cut-part-of-a-string-using-awk-752524/)

m4rtin 09-03-2009 06:24 PM

cut part of a string using awk
 
I have a file full of similar strings, which look like this:
Code:

Port::Ifindex.34
Port::Ifindex.452
Port::Ifindex.3
Port::Ifindex.9999
etc

How to cut everything other than the number after "."?

The output should be
Code:

34
452
3
9999

I don't mind reading myself, but I haven't found any good tutorial about cutting with awk. Or if someone gives an direct answer, then small explanation would be nice or additional examples ;)

kbp 09-03-2009 07:07 PM

I dont use awk much, you could use 'cut' though:

Code:

#!/bin/bash

for line in $(cat ./text_file)
do
        echo $line | cut -d. -f2
done

or

Code:

cut -d. -f2 text_file
or for g/awk:

Code:

gawk -F. '{ print $2 }' text_file
cheers,

kbp

ghostdog74 09-03-2009 07:32 PM

Code:

awk -F"." '{print $NF}' file


All times are GMT -5. The time now is 02:06 PM.