Glam Prestige Journal

Bright entertainment trends with youth appeal.

Case

I am trying to replace all occurrences of <value>*</value> into <value>file:\\</value> in a designated file test.txt.

I work on Windows and use sed I have installed with Win-32 compiled set of bash utils.

I use a following command:

sed -n "s/<value>.*<\/value>/<value>file:\\\\<\/value>/g" "test.txt" > "test.txt.new"

I want to run this command as a part of Wpkg script.

Problem

When I use this command from commandline, everything works properly.

But when I use this command via Wpkg script:

<install cmd='%BASH%\sed -n "s/&lt;value&gt;.*&lt;\/value&gt;/&lt;value&gt;file:\\\\&lt;\/value&gt;/g;" test.txt" > "test.txt new"' />

...then what I get is:

Exit code returned non-successful value (2) on command '%BASH%\sed -n "s/<value>
.*<\/value>/<value>file:\\\\<\/value>/g;" "test.txt" > "test.txt.new"'.

The above means that sed application returned exit code 2. Additionaly, the new file has not been created.

I browsed google for a really long time and to my surprise, sed seems to have a pretty poor documentation. I have found no documentation regarding this exit code.

Question

Anyone got a clue what does exit code 2 mean for sed?

...or an alternative solution?

(must be unattended, pretty sure might use common bash tools)

2 Answers

I'm not convinced that your problem is with sed. Is %BASH% supposed to evaluate to a directory in which the sed executable resides and have you confirmed that it does so? Because my expectation would be that (if defined at all on Windows) %BASH% would evaluate to the path to the bash executable itself, in which case appending "\sed" onto it makes no sense.

In particular I'll note that the DOS error code 2 is "File Not Found" - perhaps it's an issue with finding the file "%BASH%\sed"?

3

Does sed issue an exit code?

Most versions of sed do not, but check the documentation that came with whichever version you are using. GNU sed issues an exit code of 0 if the program terminated normally, 1 if there were errors in the script, and 2 if there were errors during script execution.

Source THE SED FAQ:

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy