If all the lines in the file will be structured like the example, I believe you can use the command line program cut
to treat the percent signs as field delimiters and pick the 2nd and 4th fields. So try running
cut -d "%" -f 2,4 --output-delimiter=","<file_name
Update:I don't think anything needs to be changed for the other format becausein the pattern %string%
the command above sees string
as the second field and extracts it. I tried running
echo "%string%" | cut -d "%" -f 2,4 --output-delimiter=","
and string
was printed to standard output.