I'm trying to write a sed command that replaces all commas that are not between quotes with the word 'linux'. Unfortunately, it's not working and I would like to know why.
My command:
sed -i '.bak' -e 's;,(?=([^"]*"[^"]*")*[^"]*$);linux;g' file.txt
I tested the regex (/,(?=([^"]*"[^"]*")*[^"]*$)/g) between the semicolons on regexr.com and it's working as expected. When running my command the file does not change. I'm running this command from macOS that's why I specify the backup extension.
file.txt contains the following text and the first comma should be replaced with 'linux':
a matching comma, "a non-matching comma,"
Using sed -i '.bak' -e 's;comma;linux;g' file.txt works fine and replaces both words with 'linux'.
Let me know how I could fix this? Thanks in advance!