LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
LinkBack Search this Thread
Old 10-17-2011, 04:03 AM   #1
ranjit
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Rep: Reputation: Disabled
how to use regex pattern matching to get data from file?


hi

I need pull out values from file using regex pattern matching.

ex:-
cpu_max=58000
cpu_min=12000

i need to read the file match the pattern and extract the string.since i am still a newbie in shell scripting any examples will be of great help.thanks in advance
 
Old 10-17-2011, 04:10 AM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Mint
Posts: 5,402

Rep: Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110
Well it depends on what you want to use, ie. bash, sed, awk, perl, ...

Try searching google for 'regular expressions', I am certain many of the hits will help.
 
Old 10-17-2011, 04:12 AM   #3
ranjit
LQ Newbie
 
Registered: Sep 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
i need to use bash.
 
Old 10-17-2011, 04:46 AM   #4
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Mint
Posts: 5,402

Rep: Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110Reputation: 1110
Some information on bash regular expressions can be found here.

Also the top 4 responses in google to 'bash regular expressions', one of which leads to link above, all seem very apt.
 
Old 10-17-2011, 02:09 PM   #5
theNbomr
Senior Member
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 4,506

Rep: Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602Reputation: 602
Quote:
Originally Posted by ranjit View Post
hi

I need pull out values from file using regex pattern matching.

ex:-
cpu_max=58000
cpu_min=12000

i need to read the file match the pattern and extract the string.since i am still a newbie in shell scripting any examples will be of great help.thanks in advance
The universe of regular expressions matching your data is virtually infinite. You would be well served to describe in words how you need to match your dataset. Use terminology that describes constant patterns such as 'numeric characters', 'preceding/following underscores', 'exactly matching cpu_min', etc. Expressions that describe the content and relationships of elements of your dataset will start to translate very quickly into regular expression syntax in your code. Be verbose in your description.
--- rod.
 
  


Reply

Tags
pattern


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] awk with pipe delimited file (specific column matching and multiple pattern matching) lolmon Programming 4 08-31-2011 12:17 PM
Pattern matching in a text file - use of AWK?? wtaicken Programming 19 02-06-2009 05:54 PM
Pattern matching in a bash case statement using regex ciphyre Programming 1 01-31-2009 12:20 PM
Help with pattern matching, sorting data with awk/gawk or perl placem Programming 2 09-11-2008 02:26 PM
pattern matching in file amitpardesi Linux - Software 5 02-08-2008 07:06 AM


All times are GMT -5. The time now is 03:33 PM.

Main Menu
 
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
Open Source Consulting | Domain Registration