Add double quotes to the words after given pattern

Hi,

I have a text file with different results and I would like to add single quotes to the value after the given pattern '='

This would be the original text file:

user_id=7492 and key=clickid;
user_id=7867 and key=clickid;
user_id=8649 and key=clickid;

And I would like the output to be like that:

user_id='7492' and key='clickid';
user_id='7867' and key='clickid';
user_id='8649' and key='clickid';

I will appreciate any help :slight_smile:

Regards

 sed "s/=\([^ ;][^ ;]*\)/='\1'/g" myFile
1 Like

Thanks!! :slight_smile:

sed 's/=\([^ ;][^ ;]*\)/=\x27\1\x27/g'

Hi,
what is

x27\1\x27

used for?
Regards

in double quotes, the shell can handle some characters.
\x27 this is a hexadecimal representation of the character '

1 Like

Thanks for the explanation

x27 is the hexadecimal value for the single quote character: '

For a complete set of hex, octal, decimal values for the characters of the English alphabet plus some enlightening context, check, for example, https://simple.wikipedia.org/wiki/ASCII

The \x27 must be interpreted by sed, but some versions don't - it's not standard.
But the shell treats '\'' within a 'string' as a literal '
(The first ' ends the string followed by an escaped ' followed by another ' that starts the remaining string.)
Indeed the following is portable

sed 's/=\([^ ;][^ ;]*\)/='\''\1'\''/g'
1 Like

[edit] I am mistaken, you are correct, since the \' isn't actually inside the double quoted string.