LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 02-09-2006, 08:12 PM   #1
cbriscoejr
Member
 
Registered: Sep 2004
Location: Baltimore, Md
Distribution: Red Hat
Posts: 47

Rep: Reputation: 15
pattern matching question - grep


I am trying to grep for a pattern (as01dc intel Diff) in a file called "formatted.fle". The pattern in a variable called "input_record" which is read from a file.

I have attempted several methods but no success

grep "$input_record" formatted_input.fle
returns
as01dc intel Diff 8251092
ias01dc intel Diff 96428
was01dc intel Diff 941104

The only valid one is the as01dc line

So to isolate that I try

grep - x "$input_record" formatted_input.fle

it returns nothing

grep "^as01dc intel Diff" formatted_input.fle

retrurns
as01dc intel Diff 8251092
which is OK but it needs to be a variable after that carat.

grep "^$input_record" formatted_input.fle

returns nothing

I don't understand why the -x doesn't work. I don't understand how to use the carat.

I am but in 3 days I have not figured it out
 
Old 02-09-2006, 08:30 PM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 40
Try using the -w option to have grep match on complete words: grep -w "$pattern" 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
Perl Pattern Matching Question pete1234 Programming 2 08-27-2005 10:26 AM
list files NOT matching a pattern smart_sagittari Linux - Newbie 9 05-20-2005 05:32 AM
Pattern Matching Help in Bash script cmfarley19 Programming 1 04-07-2004 09:22 AM
pattern matching in perl ludeKing Programming 9 04-02-2004 09:53 AM
Doubt in Pattern matching and vi editor.. suriyamohan Linux - General 2 08-19-2003 05:03 AM


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