[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: grep help with cygwin

From: Benno Schulenberg
Subject: Re: grep help with cygwin
Date: Thu, 03 May 2007 19:29:01 +0200
User-agent: KMail/1.9.6

sdnabble wrote:
> I want to first parse through File1.txt and find all the lines
> missin the XY information.

$ grep -v X.Y. File1.txt

> Then find that same string in 
> file2.txt that have the needed XY information.

Difficult.  If those strings were on lines by themselves, it 
would be easy.  Now you have to find a way to only grab the 
"Some_string_n" part.  If this "_1", "_2" are a distinguishing 
trait, then this would work:

$ grep -v X.Y. File1.txt | grep -o ".*_[0-9]"

If that produces the expected set of strings, then do:

$ grep -v X.Y. File1.txt | grep -o ".*_[0-9]" | grep -F -f - File2.txt
inst "Some_string_1" PLACED in X2Y1;
inst "Some_string_2" PLACED in X3Y1;

> And finally append 
> the information to file1.txt

Use '>>' to pipe the output there:

$ grep -v X.Y. File1.txt | grep -o ".*_[0-9]" | grep -F -f - File2.txt 

> grep "Some_String_" file1.txt | grep [^P]LACED > tempout.txt
> Right away it didn't work. For some reason I can't say look for
> Some_String_ NOT containing the word PLACED.

Use the option '-v' to look for lines _not_ containing a pattern.

> Isn't that how to use "NOT"?

'grep [^P]LACED' looks for the patterns aLACED, bLACED, cLACED, and so on,
it looks for every occurrence of .LACED, excepting PLACED.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]