0

I have the example text:

"are "insulin sensitizers" "

I am trying to use the below command to find and replace the xml quote command with a single quote but it only works for the first one and the second that follows "sensitizers" is left unchanged.

command:

grep -rl """ ./ | xargs sed -i "s/"/'/" 

result:

"are 'insulin sensitizers" "

desired result:

"are 'insulin sensitizers' "
seanysull
  • 720
  • 1
  • 8
  • 24
  • 3
    `sed -i "s/"/'/g"` (global) – anubhava Apr 30 '18 at 14:02
  • 2
    Possible duplicate of [Bash script to convert from HTML entities to characters](https://stackoverflow.com/questions/5929492/bash-script-to-convert-from-html-entities-to-characters). Amusingly, the question ends with "*how can this be accomplished without using cryptic regex?*" – sshine Apr 30 '18 at 14:39
  • 1
    cryptic regex could be a great supervillain, @anubhava if you'd like to put your comment as an answer I woud be happy to accept it as it has solved my problem. – seanysull Apr 30 '18 at 16:09

1 Answers1

0

You will need to use g flag in sed for global substitution:

grep -Zirl """ . | xargs -0 sed -i "s/"/'/g"

Also note use of -Z option in grep and -0 in xargs to take care of files with special characters and whitespaces.

As per man grep:

-Z, --null

Output a zero byte (the ASCII NUL character) instead of the character that normally follows a file name.

Community
  • 1
  • 1
anubhava
  • 761,203
  • 64
  • 569
  • 643