I have a list as below;
paramone=somerandomvalue; paramtwo=somerandomvalue; paramthree=somerandomvalue;
I want to append a * (asterisk) at the end of every 'somerandomvalue' but before ; (semicolon) like below -
paramone=somerandomvalue*; paramtwo=somerandomvalue*; paramthree=somevrandomalue*;
NOTE - It should only append the strings that have = and ; . There are other strings having ; at the end but doesn't have a =.
CodePudding user response:
I'd leverage sed
to do this:
sed 's/;/*;/g' test.txt
Something like that. Assuming every value has that ;
at the end of it.
CodePudding user response:
Assuming your input had the following content
$ cat input_file
paramone=somerandomvalue; paramtwo=somerandomvalue; paramthree~somerandomvalue;paramone=somerandomvalue; paramtwo=somerandomvalue; paramthree##somerandomvalue;
Using sed
$ sed s'/\(=[^;]*\)/\1*/g' input_file
paramone=somerandomvalue*; paramtwo=somerandomvalue*; paramthree~somerandomvalue;paramone=somerandomvalue*; paramtwo=somerandomvalue*; paramthree##somerandomvalue;
CodePudding user response:
This should also work -
sed s'/=\(.*\)?;/\1*/g' <input_file_name>