[SGVLUG] Grep and the command line...

Jeremy Leader jleader at alumni.caltech.edu
Fri Jun 1 12:58:12 PDT 2007


grep doesn't need forward slashes around its pattern, but you probably need a 
backslash in front of the quote, or put it inside single quotes.

If you're using bash, you can use Ctrl-V to insert a literal character (like a 
tab).  In order not to be ignored by the shell as whitespace between options, it 
has to be escaped or quoted.

So I'd type:

grep '<Ctrl-V><Tab>"' CV5055_active.tab

(where <Ctrl-V> means press control-V, and <Tab> means press tab).

If you don't like single quotes, you could use backslashes:

grep \<Ctrl-V><Tab>\" CV5055_active.tab

Either version should work in bash; the backslash version probably won't work in 
an old-school DOS command prompt.

-- 
Jeremy Leader
jleader at alumni.caltech.edu
leaderj at yahoo-inc.com (work)

on 06/01/2007 12:41 PM Emerson, Tom (*IC)  wrote:
> Actually, I want to find where a quote immediately follows a tab -- the
> "normal" case is that it doesn't, so "tab only" searching would find
> every line in the file.
> 
> In any case, the real difficulty comes in specifying the quote character
> -- remember, this is being done in DOS, not bash/ksh/csh/whatever-sh.
> When I type in this:
> 
> C:\> grep /"/ CV5055
> 
> And then press <tab> [to auto-complete the filename] it changes to this:
> 
> C:\> grep /"/"CV5055_active.tab"
> 
> Thus making the filename part of the search string and not the actual
> target of grep.
> 
> ==========
> 
> OK, Specifics: here is -ONE- record that is causing a problem:
> 
> C:\Vanguard\EXTRACTS\CR2>grep "T1202 00TR" CV5055_active.tab
>         T1202 00TR  01  "DISP 12CT TRAY 0       EA  [...snip...]
> 
> C:\Vanguard\EXTRACTS\CR2>grep "T1202 00TR" CV5055_active.tab | OD -c
> 0000000       \t   T   1   2   0   2       0   0   T   R           0   1
> 0000020   \t   "   D   I   S   P       1   2   C   T       T   R   A   Y
> 0000040   \t   0  \t   E   A  \t      [snipped here]
> 
> Note the second line of the dump begins with a tab (\t) followed
> immedately by a quote character -- that's the pattern I want to find
> elsewhere in the file.
> 
> It seems the DOS version of grep doesn't understand "\t" as "tab", which
> also makes things tough to find...
> 
>> -----Original Message-----
>> From: sgvlug-bounces at sgvlug.net 
>> [mailto:sgvlug-bounces at sgvlug.net] On Behalf Of BB Odenthal
>> Sent: Friday, June 01, 2007 11:50 AM
>> To: SGVLUG Discussion List.
>> Subject: Re: [SGVLUG] Grep and the command line...
>>
>>
>> The extended regex /\t"?/ will search for a tab followed by 
>> zero or one double quotes. So this will match the following:
>>
>> <Tab>"
>> <Tab>
>>
>> You can also write it as /\t"{0,1}/
>>
>> -bb
>>   
>>
>> -----Original Message-----
>> From: "Emerson, Tom (*IC)" <Tom.Emerson at wbconsultant.com>
>> Date: Fri, 1 Jun 2007 11:37:16 
>> To:"SGVLUG Discussion List." <sgvlug at sgvlug.net>
>> Subject: [SGVLUG] Grep and the command line...
>>
>> First off, I'll admit I'm NOT a regex "guru", but I'm getting 
>> better. Now I have a search that sorta has me stumped (and 
>> part of the problem is that I'm doing this using the 
>> microsoft "SFU"(*) version of grep at the DOS command line)
>>
>> Here's the deal: I have a tab-delimited file that appears to 
>> have a mismatched "quote" somewhere.  For example, the file 
>> /should/ look like
>> this:
>>
>>
>> -->key   <tab>description.....      <tab>123<tab>456<tab>etc.
>>
>> Note that "description" is an essentially free-form text 
>> field.  Any actual "tabs" in the data (description) have been 
>> converted to "<t>". Somewhere in the file I have this:
>>
>> -->key   <tab>"description....       <tab>123<tab>456<tab>etc.
>>
>> Note the subtle inclusion of a double-quote character at the 
>> begninning of the description, but not at the end.  This 
>> "quote" character is part of the actual data.  As a result, 
>> the process importing the file sees the initial quote 
>> character, strips it from the field, and looks for a 
>> corresponding close-qoute.  Since it doesn't see it before 
>> the CR/LF, it includes THE REST OF THE LINE as part of the 
>> description!
>>
>> So, how do I search for the sequence <tab><double-quote>?
>>
>> Bonus points for "how do I actually type this in at a command 
>> line"? (using the aforementioned DOS command line and 
>> Microsoft's version of
>> grep?)
>>
>> Tom
>>
>> (*) SFU = Services for Unix -- a freebie from MS that 
>> includes a bash shell, tab-completion [within DOS!] and a 
>> fairly standard assortment of "basic tools"



More information about the SGVLUG mailing list