Hi,

similar but slyghtly shorter than Matthews solution to cut the 7th column from a csv file:

Search for:
^((?:.+?,){6}).+?,(.+)

Replace with:
\1\2


Note that the ?: excludes the enclosing parantheses from usage in the replace section and is not necessarily needed. One could also search for
^((.+?,){6}).+?,(.+)
but you would have to replace with
\1\3

I highly recommend the excellent "Grep Reference" Part of BBEdit's manual. The time needed to work through it will pay off exponentially.

Happy greping
Roland


Am 18.01.2007 um 14:53 schrieb Matthew Fischer:

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



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