On 07/20/10 16:59, Suhas Chakravarty wrote:
Hi
I am working with FPGA's and need to extract a count of number of resources
used from an implmentation report. A sample line from the report looks like

inst "IoPort2Wrapperx/IoPort2x/IoReceiveFifoEndx/bReadOutputRecord_Data<63>"
"SLICEM",placed CLBLM_X42Y87 SLICE_X56Y87  ,
.

I need to search for the pattern "placed CLB*" in the whole file and count
its occurrences. But I need to make sure that repititions of CLB names (for
example CLBLM_X42Y87) are NOT counted twice. Can I do this in Vim? Or am I
better off writing a script for this?

I think if I understand you, you can do something like

  :let matches={}
:%s/\<placed \zsCLB_\w+/\=extend(matches, {submatch(0):submatch(0)}, 'force')[submatch(0)]/g
  :echo len(matches)

This does the following:

1) create a Dict in which to store matches (Dictionaries take care of making duplicates unique)

2) find all your matches and place them in the dict with a little hack

3) find the number entries that were put in "matches" and do something with it (in this case, just echo it).

If case should be ignored, you can change it to something like

extend(matches, {tolower(submatch(0)):submatch(0)}, 'force')[tolower(submatch(0))]


It has the unfortunate side-effect of setting the 'modified' flag since it's actually doing the replacement, however it replaces the match with exactly what it found so it doesn't actually produce real changes in the file. If you feel unsettled, you can always just hit "u"ndo afterwards.

-tim





--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to