LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-05-2006, 08:11 AM   #1
meniscus
Member
 
Registered: May 2006
Posts: 70

Rep: Reputation: 15
using awk


Is there a way of using awk to get a specific number embedded in a line of text?

Code:
xyz90ghtj









g Tool

Monitor Wind
 
Old 10-05-2006, 09:33 AM   #2
b0uncer
LQ Guru
 
Registered: Aug 2003
Distribution: CentOS, OS X
Posts: 5,131

Rep: Reputation: Disabled
I think sed (stream editor) and grep would help you more, since awk is something more complex...the simplest solutions are often the best.
 
Old 10-05-2006, 09:33 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
yes certainly, but you need to give more infomration about your input data, every permutiation opf styles and formats so we know how to handle the data.
 
Old 10-05-2006, 09:33 AM   #4
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 38
Hey!
What do you want to select on:
1) it being a number? or
2) something coming after xyz?
Type a bit more, specific information would help
 
Old 10-05-2006, 11:11 AM   #5
meniscus
Member
 
Registered: May 2006
Posts: 70

Original Poster
Rep: Reputation: 15
Its not for anything in particular. I read that you can take a word out of a string in a file using awk and the $ operator.I was just wondering if you had a word or sentence in a file like "voltage=12V" how would you get the 12V from it? As in if the 12V could not be distinguished by the "$" operator
 
Old 10-05-2006, 12:31 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984Reputation: 1984
well i think this is basically "what is a regular expression?" in a different form...
 
Old 10-05-2006, 12:39 PM   #7
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Quote:
Originally Posted by meniscus
Its not for anything in particular. I read that you can take a word out of a string in a file using awk and the $ operator.I was just wondering if you had a word or sentence in a file like "voltage=12V" how would you get the 12V from it? As in if the 12V could not be distinguished by the "$" operator
As kewp said: it's about regular expressions, plus maybe
the various separators awk knows about. $, btw, is not an
operator, it's a field denominator.

In this case something like
awk -F= '{print $2}'
will do.



Cheers,
Tink
 
  


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
awk question davidkline Linux - General 9 09-29-2006 12:37 PM
awk on a variable onradius Programming 8 02-22-2006 08:34 AM
awk question denalitastic Linux - Newbie 1 06-07-2005 10:42 AM
using awk wedgeworth Linux - Newbie 9 02-20-2004 07:48 AM
awk problem alaios Programming 4 05-04-2003 09:46 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:59 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