Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 02-09-2006, 08:12 PM   #1
Registered: Sep 2004
Location: Baltimore, Md
Distribution: Red Hat
Posts: 60

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
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

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
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Try using the -w option to have grep match on complete words: grep -w "$pattern" file


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:17 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration