Sample Header Ad - 728x90

Change a double quote into a single quote with gnu sed when the quotes come before and after a parenthesis?

1 vote
6 answers
603 views
I'm using Debian 12 bookworm, gnu sed. I have this
-none
"Hello1"
"('41-Z', 5001, 'A6')" 
"'Hello2'"
"('42-Z', 5002, 'A7')"
'Hello3'
"('43-Z', 5003, 'A8')"
I want to modify only the lines with parenthesis entries, to appear like this:
-none
"Hello1"
'('41-Z', 5001, 'A6')'
"'Hello2'"
'('42-Z', 5002, 'A7')'
'Hello3'
'('43-Z', 5003, 'A8')'
How can I used sed to trade out the double quotes for single quotes of the lines in this example that have parenthesis, without interfering with the quotes of the other lines? This is a large text file that has hundreds, maybe thousands of these entries. I prefer sed, but I also tried looking for answers that use tr (truncate). Maybe someone has an awk answer.
Asked by shrykullgod (39 rep)
Jul 13, 2025, 11:18 PM
Last activity: Jul 16, 2025, 10:07 AM