Question

I have a whole bunch of files that all have blocks of text in them that look like this:

"Each file has different text between the opening double-quote
and the closing right-quote (or whatever it's called)”

Perhaps not relevant, but in the past I have used grep to do a search and replace like this:

grep -Rl 'search' ./path/to/files/ | xargs sed -i 's/search/replace/g

Is there any way to do something similar, but use a regex to replace the opening plain old double-quote with a left-quote ()? The only reliable way to replace the correct double-quote characters is to search on the right-quote, then backwards tot he previous double-quote. I think. I'm just not sure if that's possible or how to do it.

I could just do it with a PHP script, but then I wouldn't get to see if it's possible from the command line.

Was it helpful?

Solution

You can use sed:

sed -i.bak 's/"\([^”]*”\)/“\1/' file

cat file
“Each file has different text between the opening double-quote and the closing right-quote (or whatever it's called)”
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top