LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 01-20-2007, 11:32 PM   #1
opto
Member
 
Registered: Jun 2006
Location: Pennsylvania
Distribution: Slackware64 , OS X , OpenBSD
Posts: 56

Rep: Reputation: 15
Question about grep & backreferences


I am practicing using grep and trying to find the line with two occurrences of why in a file called learn_grep.txt. I thought I typed the proper commands, but according to my results I am not. Here is what the line looks like in the text file:
Quote:
why ask why
I type this into bash:
Code:
usr@terminal:$ grep \(why\).*\1 learn_grep.txt
It does not echo any line in learn_grep.txt.

I tried to look it using google.com/linux and linuxquestions.org but I could not find my problem.

Does anybody know what I am doing wrong?
 
Old 01-21-2007, 12:09 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
Try putting quotes around your grep pattern to avoid shell expansion of special symbols in it.
 
Old 01-21-2007, 12:24 AM   #3
opto
Member
 
Registered: Jun 2006
Location: Pennsylvania
Distribution: Slackware64 , OS X , OpenBSD
Posts: 56

Original Poster
Rep: Reputation: 15
Worked

Code:
$ grep '\(why\).*\1' learn_grep.txt
why ask why
Man, forgot about the quotes. Thank you.
 
  


Reply



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
maybe a grep question: me210 Linux - Software 3 01-19-2007 12:13 PM
grep [A-Z] & [a-z] match both upper and lower case. jschiwal Linux - General 4 05-28-2005 06:43 AM
grep question djgerbavore Linux - Newbie 7 07-07-2004 07:11 AM
grep question vasanthraghavan Programming 3 04-23-2004 12:32 AM
sed & grep script? dolvmin Linux - Software 20 09-22-2003 06:30 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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