Question

Am using sed to build URLs with percent codes. Chemicals may be represented using the simplified molecular-input line-entry system (SMILES). See: http://en.wikipedia.org/wiki/SMILES

Here is the SMILES code for the chemical iron-sulfur-molybdenum cofactor:

[O-]C(=O)CCC1(CC([O-])=O)O[Mo]23(OC1=O)[S]1[Fe]45S[Fe]67[S]8[Fe]9[S]6[Fe]6%10S[Fe]%11([S]24)[S]3[Fe]11S[Fe]8([S]96)[N]57%10%111

Some chemical sites allow access using SMILES in a URL. As you can see (following the atoms [Fe]6 and [N]57) SMILES may include the percent % symbol.

I need to convert the % symbol to its URL escape code %25. I'm using GnuWin32 sed version 4.1.5.4013 in Windows 7. I have this sed script:

sed -e "s/\%/\%25/g" < C:\1.txt > C:\2.txt

But it returns this error message:

sed: -e expression #1, char 6: unterminated `s' command

Further, when I look at the script in command mode I see:

sed -e "s/\25/g" C:\bin\1.txt > C:\bin\2.txt

So clearly the % symbol is being stripped away.

How to modify the sed script to convert a SMILES string to include URL escape codes that begin with the symbol %.

Also am willing to use awk or gawk.

Thank you in advance for an answer.

Was it helpful?

Solution

Syntax for the Windows command shell:

sed "s/%/25%/g" file

Syntax for a Windows command shell ('batch') script:

@ECHO OFF &SETLOCAL
sed "s/%%/25%%/g" file
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top