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.

--
------------------------------------------------------------------
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