I want to change in file in each line the last match to the XXXX Given the file format:
"192.xx2" "someting" "another2321SD"
I want to have:
"192.xx2" "someting" "XXXX"
only using sed My solution:
sed -r 's/"(?:.(?!".+"))+$/XXXX/' file
I want to change in file in each line the last match to the XXXX Given the file format:
"192.xx2" "someting" "another2321SD"
I want to have:
"192.xx2" "someting" "XXXX"
only using sed My solution:
sed -r 's/"(?:.(?!".+"))+$/XXXX/' file
Remember what was there before the last pair of double quotes in a capture.
sed -r 's/^(.*)"[^"]*"$/\1"XXXX"/'
Please bear in mind that
(?:...)
is a non-capturing group and POSIX regex does not support this construct(?!...)
is a negative lookahead and POSIX regex does not support this construct either.To mask all content in between the last pair of double quotation marks, you can use
sed -r 's/(.*)".*"/\1"XXXX"/' file
sed 's/\(.*\)".*"/\1"XXXX"/' file
See the sed
demo:
s='"192.xx2" "someting" "another2321SD"'
sed -r 's/(.*)".*"/\1"XXXX"/' <<< "$s"
# => "192.xx2" "someting" "XXXX"