On 1/18/07 at 8:53 AM, [EMAIL PROTECTED] (Matthew Fischer)
wrote:

On Jan 18, 2007, at 7:53 AM, Bill Rowe wrote:

I often have need to manipulate data formated as comma separated
fields with each line being a separate data record. Sometimes I
want to delete a field from the file. Say I want to delete the 7th
item. Currently, I do this in several steps,

search for ^(.+?,){6} and replace with &b search for ^(.+?,){7} and
replace with &b search for b.+b and replace with nothing

The first two steps simply surround the field I want to delete with
a character not found in the file. This makes it trivial to delete
the field I want deleted.

I am would like to know if there is a more efficient (fewer steps)
way to achieve this with grep.

There is probably a better way to do this, but this deletes the 7th
item in a comma separated row:

Find: ^([^,]*,[^,]*,[^,]*,[^,]*,[^,]*,[^,]*,)[^,]*, Replace: \1

The find starts at the beginning of a line and looks for seven
instances of zero or more characters that aren't commas followed by
a comma. The first six are captured by the () and used for the
replace with the \1.

Yes, this will definitely work in one step. But it is quite painful if say I am working with records with say 25 fields and I need to delete the 19th field from the start. Not only is there the pain associated with having to type the search string but there is the difficulty of verification.

When I search for ^(.*?,){18}, I can easily see it will match the first 18 fields. But, it would not be easy to see the difference between a series of 17 [^,]*, patterns and 18 of them. I was hoping someone could suggest a more elegant compact solution that took fewer steps than the approach I am using.

What I would like to be able to do is something like

Find ^(.*?,){6}.*?,(.*) and
Replace with something representing just the portion of the pattern set off by "(" and ")"

The search pattern is easy. I haven't figured out the replacement pattern. And it may well not be possible to do what I would like in a single step.

--
------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_talk.shtml>
List archives: <http://www.listsearch.com/BBEditTalk.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to