LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-03-2009, 07:24 PM   #1
m4rtin
Member
 
Registered: Sep 2007
Posts: 261

Rep: Reputation: 16
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
 
Old 09-03-2009, 08:07 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,758

Rep: Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644Reputation: 644
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

Last edited by kbp; 09-03-2009 at 08:22 PM.
 
Old 09-03-2009, 08:32 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
Code:
awk -F"." '{print $NF}' file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use command grep,cut,awk to cut a data from a file? hocheetiong Linux - Newbie 7 09-11-2008 08:16 PM
how to cut first four digit of a string kkpal Linux - Newbie 3 07-22-2008 03:32 AM
String manipulation (subst for cut) EmLS Programming 4 08-16-2007 01:53 AM
Part of screen cut off moo-cow Ubuntu 4 05-03-2006 06:49 PM
cut / awk command?? Sammy2ooo Linux - Newbie 1 05-27-2003 06:46 PM


All times are GMT -5. The time now is 10:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration