[Nottingham] Howto delete chars from midway into lines of text?

Camilo Mesias camilo at mesias.co.uk
Thu May 6 12:51:39 UTC 2010


Something like that, although you should only collect the things you
want to keep with the \( \)
So if you wanted to strip quotes from the second column you could use:

 sed 's/\("[^"]*",\)"\([^"]*\)"/\1\2/' quoted.txt

For the third column you would have to increase the first match to
have more "[^"]*", bits (ie. matching a double quote, as many as
possible non-quote characters, another double quote and a comma:

sed 's/\("[^"]*","[^"]*",\)"\([^"]*\)"/\1\2/' quoted.txt

In the above, \1 refers to the columns you are matching with the first
brackets (ie. the ones left alone) and the \2 refers to the second
brackets - ie contents of the column that is having the quotes
removed. You don't have to worry about the subsequent columns.

It's pretty fragile though, I'm not sure what the syntax is for a
string that contains a " - that would break the sed script. Also, any
spaces in between quotes and commas will break things.

-Cam



More information about the Nottingham mailing list