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, 09: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, 10: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, 10:33 AM   #3
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974Reputation: 1974
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, 10:33 AM   #4
muha
Member
 
Registered: Nov 2005
Distribution: xubuntu, grml
Posts: 451

Rep: Reputation: 37
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, 12:11 PM   #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, 01:31 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

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

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


All times are GMT -5. The time now is 01:50 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration