1

I have this string for example :

asddsa "ll" sadd " fsgsg"
"sdafaf" "lkkx" "fsgfgsg"

I want to substitute all characters inside " " with a character x. Expected output in this case should be:

asddsa "x" sadd " x"
    "x" "x" "x"

I tried something like this : sed 's/".*"/"x"/g' but the output is logically

asddsa "x" "x"

How could I fix my regexp to get the right output?

2

A dot . means any character. But you don't want it to match a double quote; you want it to match anything but a double quote. So specify that with a character class:

sed 's/"[^"]*"/"x"/g'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.