LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 12-08-2004, 11:11 AM   #1
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

Rep: Reputation: 32
How to use grep to look for files that have linex and liney


How can I use grep to find all files that have linex and liney ?
But not files that only have one of them ?

Thanks in advance.
 
Old 12-08-2004, 11:17 AM   #2
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
grep 'linex\|liney' <files> or, to impress your friends grep 'line[xy]' <files>

You may have to escape the '|' more (or less) depending on your shell.

Last edited by sigsegv; 12-08-2004 at 11:20 AM.
 
Old 12-09-2004, 03:50 AM   #3
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

Original Poster
Rep: Reputation: 32
Thanks but on Tru64 Unix this does not work.
 
Old 12-09-2004, 04:22 AM   #4
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
:-)
You might want to specify why this doesn't work for you. That'll help improving sigsegv's proposal.

Anyway, I'd suggest
Code:
grep -l linex <files> | xargs grep -l liney
I hope your filenames don't have spaces in them, otherwise this won't work either.

Groetjes,

Kees-Jan
 
Old 12-09-2004, 05:08 AM   #5
davholla
Member
 
Registered: Jun 2003
Location: London
Distribution: Linux Mint 13 Maya
Posts: 729

Original Poster
Rep: Reputation: 32
The first one did not work because to test it I created 3 files testgrepx (x = null,1,2). One file had linex, one file line y and one both lines as sperate lines.
grep linex path/* found 2 files grep liney path/* found 2
but grep 'liney\|linex' path/* did not find any but did not give an error.

However your command did work thanks a lot and also thanks sigsegv. Maybe his did not work as I am using Tru64
 
Old 12-09-2004, 05:50 AM   #6
sigsegv
Senior Member
 
Registered: Nov 2004
Location: Third rock from the Sun
Distribution: NetBSD-2, FreeBSD-5.4, OpenBSD-3.[67], RHEL[34], OSX 10.4.1
Posts: 1,197

Rep: Reputation: 47
Quote:
Originally posted by davholla
Thanks but on Tru64 Unix this does not work.
Probably not escaped right for your shell. Getting regexes through the shell properly can be a bite sometimes...

If you can get it escaped right though, it's pretty standard. Should work fine just about anywhere.

Last edited by sigsegv; 12-09-2004 at 05:52 AM.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can you specify which files to grep search? sneakyimp Linux - Software 4 10-12-2005 08:28 PM
cp files from grep results Sigkill(9) Linux - Newbie 2 08-22-2005 03:17 PM
Using grep to change multiple files zwyrbla Linux - General 5 01-11-2005 02:14 PM
grep on Unicode files overbored Linux - Software 2 07-18-2004 01:12 PM
How to filter files in files and files which are in a sub-directory with "grep"? Piero Linux - Newbie 9 08-29-2003 02:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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