LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 06: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, 07:07 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
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 07:22 PM.
 
Old 09-03-2009, 07:32 PM   #3
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

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


Reply



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 07:16 PM
how to cut first four digit of a string kkpal Linux - Newbie 3 07-22-2008 02:32 AM
String manipulation (subst for cut) EmLS Programming 4 08-16-2007 12:53 AM
Part of screen cut off moo-cow Ubuntu 4 05-03-2006 05:49 PM
cut / awk command?? Sammy2ooo Linux - Newbie 1 05-27-2003 05:46 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:37 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
Open Source Consulting | Domain Registration