59567Re: finding null fields in bar-separated records
- May 31, 2005On Tue, 31 May 2005 at 6:46am, jkilbour@... wrote:
> I would like to identify the null fields in a set of files (which haveDepending on what exactly you want to do with them, you might be able to
> different numbers of fields; i.e. to find not just the number of fields
> that are null but also which fields are null. Is this possible using vim
> regular expressions?
create multiple solutions. May be you can first number all of the fields
and then search for those that are empty to lookup them up.
let g:idx = g:idx + 1
let match = submatch(1)
return (match == '' ? g:idx.':'.'<null>' : match)
let g:idx = 0 | s/|\([^|]*|\@=\)/\='|'.Submatch()/g
The above will transform
All that you need to do then is to search for nulls using a pattern such
as "\d\+:<null>". The actual regex to use to do the above substitution
will depend on exact specifications, such as can you have a "|"
character inside a field, and if so how you escape them. I am not a
regex guru myself, but if you need further help, you can describe your
needs in more details, for me or others on the list to come up with the
There are many regex gurus on this list, so I won't be surprised to see
a much simpler/easy to use solution. However, if you want to deal with a
programmatic approach, you can take a look at my multvals.vim plugin to
iterate over the fields and do something with them.
call MvIterCreate('|one|two|three||five||seven|', '|', 'Iter')
let n = 0
let ele = MvIterNext('Iter')
if ele == ''
echo 'Found null at: ' . n
let n = n + 1
PS: Multvals treats the first "|" in the string also as a separator
resulting in one extra field, but you should be able to workaround that.
Do you Yahoo!?
Yahoo! Small Business - Try our new Resources site
- << Previous post in topic Next post in topic >>