ZTree.com  | ZEN  | About...  

 Index   Back

[Help!] Search string with asterisks   [Help!]

By: Ben Kent       
Date: Jun 03,2014 at 22:57
In Response to: [Help!] Search string with asterisks (David Bullock)

> Good day, all!
> I've got several hundred pipe-delimited data files, with the list
> growing hourly each day. Among the 22 fields on each line is field 8: a
> "status" field which contains values including "V" for Void; and
> field 12: a "Method" field, which contains values including "V" for
> Visa. There are numerous name, date, amount, etc fields on both sides of
> both fields. A mocked-up record might look like this:
> 111|222|333|444|555|666|777|V|999|aaa|bbb|V|ccc|ddd|...etc out to 22
> fields.
>
> I am trying to find the files containing Void records in the 8th
> "status" field. I cannot simply search for "|V|", because the 12th
> field "method" can also contain "V".
>
> I tried searching for "|V|*|[CV]|" (using the alt-[ and alt-]
> characters) to find Void records where the method field contains either C
> or V, but apparently this construction does not work for text searches
> the way it does for filename filtering.
>
> So I thought I'd try to force it to find "V" in the 8th field by
> also searching for enough pipe symbols to account for the rest of the 22
> fields in the line. By my count, I would need twelve asterisks
> ("|V|*|*|*|*|*|*|*|*|*|*|*|*|") to find those lines with "V" in the
> status field. However, a search string containing nine asterisks was the
> largest string that provided any hits. Ten or more just goes through the
> file without any hits at all.
>
> Anyone have any other ideas? Other than the pipe symbols, there is no
> consistent text to force the search to find "V" in only the 8th field.
>
>
> HELP!
> Thanks,
> -David B
> (too much detail? sorry, not sure what might be the needed clue...)

David

If you search for |*|V| you will see that the text that is highlighted is from the 4 character to the second V, not what you need, as the * wildcard is greedy and matches as much as possible.

I suspect that ZTree cannot do what you want, it has no line being or end markers, and no character classes so * matches all characters.
Regular expressions have been requested many times before for use as filespec and for search, but have not arrived yet.


If you don't mind going outside of ZTree then these commands do what you need
pushd c:\dir
findstr /s /m /r /b "[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|V|" "*.*"

or with a bit for FOR command magic, you could make a ZLIST file that you could use to tag the matching files in ZTree
pushd c:\dir
del Matches.ZLS
for /f "tokens=*" %I in ('findstr /s /m /r /b "[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|[^|]*|V|" *.*') do echo T=%I>>Matches.ZLS


the switches
/s recurse (optional)
/m only print the matching filename, not the matched lines
/r use regular expressions
/b from the beginning of each line
the regular expression
[^|] character class containing all but the | character
* zero or more of them
| literal character
then the filename wild card

if you don't need to recurse then your can skip the pushd and specify the fullpath with the filename wild card

Ben

757 views      
Thread locked
 

Messages in this Thread

 
96,637 Postings in 12,231 Threads, 350 registered users, 111 users online (0 registered, 111 guests)
Index | Admin contact |   Forum Time: Mar 29, 2024 - 2:48 pm UTC  |  Hits:62,409,558  (24,344 Today )
RSS Feed