fork download
  1. #!/bin/bash
  2. s='"1"|"Text"|"a"
  3. "2"|""Text in quotes""|"ab"
  4. "3"|"Text "around" quotes"|"abc"
  5. "4"|""Text `in` quotes""|"ab"
  6. '
  7. perl -pe 's/(?:^|\|)(")?\K(.*?)(?=\1(?:$|\|))/$2=~s#"|(`)#`$1#gr/ge' <<< "$s"
  8.  
Success #stdin #stdout 0s 19632KB
stdin
Standard input is empty
stdout
"1"|"Text"|"a"
"2"|"`Text in quotes`"|"ab"
"3"|"Text `around` quotes"|"abc"
"4"|"`Text ``in`` quotes`"|"ab"