Reputation: 1172
noob question.
I would like to replace all the @
by ”,”
if the character before @
is not ”
To increment this command cat foo.csv | sed 's/@/","/g'
Upvotes: 2
Views: 220
Reputation: 626920
You can use
sed -r 's/(^|[^"])@/\1","/g'
where (^|[^"])
is a group matching either the start of a line or a character other than "
. The \1
is a backreference to the Group 1 (either an empty string or a char matched with a [^"]
bracket expression).
For an alternative syntax without -r
, see Kent's comment (you will need to escape the special characters like (
, )
, |
for them to behave as special regex metacharacters).
Upvotes: 2