If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > grep and then count some char..

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-04, 07:44
ChiLLinG ChiLLinG is offline
Registered User
 
Join Date: Feb 2004
Posts: 1
grep and then count some char..

Hi,
i have a little problem here.
I've written a little shell script which gets the path to some files out of a file list.txt and there is another file key.txt with keywords which should be looked for in the files of list.txt.

That works fine, but in some of the files of list.txt there a lines like:
ads'asdf asdfasdf 'asdf 'Asdf 'asdf 'this'Adadf
and if the keyword this was used grepping that file, it surely will be found in that file.
The problem is, that this is in ' ' and doenst count in this case...

I could solve that problem by counting ' in that line, and if ' appears 2, 4, 6 ... times before this, it counts and if ' appears 3, 5, 7 .. times infront of this, this will be in ' ' and doesnt count!

How can I do that?
Reply With Quote
  #2 (permalink)  
Old 02-18-04, 08:17
S_Scheible S_Scheible is offline
Registered User
 
Join Date: Feb 2004
Posts: 17
Uh, sounds nasty. I think a regular expression might help, you are likely searching for (pseudocode)
Code:
Zero or more times (One ' followed by zero or more characters followed by one ') followed by KEYWORD followed by zero or more characters
While I am thinking about it, some weird hacks using awk (print all even parameters, where parameters are separated by ') might work either but you'ld have to get back the original line if you find a match.
Pick one and I will elaborate (or you can probably find more on either topic at google).
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On