0

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.

1
  • This looks like it's more a Windows scripting issue than a sed issue. Commented Aug 12, 2013 at 17:49

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

@Endoro: What happened with your old avatar with your photo?
@Aacini time to change after 1/2 year at SO :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.