Operating System - HP-UX
1761417 Members
2583 Online
108901 Solutions
New Discussion юеВ

sed command cannot be parsed

 
SOLVED
Go to solution
Shane Coombs
Occasional Contributor

sed command cannot be parsed

All,
I have a sed command that works fine on both Solaris and Linux, but fails on HP-UX. It is for a nightly build process, and is the last piece that I need to port. I am not extremely familiar with sed, so bombard me with corrections! :D

The sed statement is:
sed '/build.rev/c\build.rev = '"$BUILD_ID"'' $BUILD_ID_FILE > $BUILD_ID_FILE.1

I had our admin apply both PHCO_22800 (sed cumulative patch) and PHCO_22760 (libc cumulative patch), but it did not help.
If there are any other sed related patches I can apply, let me know as well.
--
Shane
6 REPLIES 6
Sridhar Bhaskarla
Honored Contributor

Re: sed command cannot be parsed

Shane,

It would help if you can give your BUILD_ID_FILE and let us know what you are trying to do.

To replace something with a variable you will need to use ' (single quotes) not the double quotes "

for ex., yours would be

sed 's/build.rev/build.rev = '$BUILD_ID'/' $BUILD_ID_FILE


-Sri
You may be disappointed if you fail, but you are doomed if you don't try
David Lodge
Trusted Contributor

Re: sed command cannot be parsed

You're not executing the sed c command properly - you need to put a line feed after the \:

sed '/build.rev/cbuild.rev = '"$BUILD_ID"'' $BUILD_ID_FILE > $BUILD_ID_FILE.1

BTW the last two '' aren't required :-)

dave
David Lodge
Trusted Contributor
Solution

Re: sed command cannot be parsed

oops sorry looks like the parse has got rid of the backslash:

sed '/build.rev/c\build.rev = '"$BUILD_ID"'' $BUILD_ID_FILE > $BUILD_ID_FILE.1
Shane Coombs
Occasional Contributor

Re: sed command cannot be parsed

The build file is:
#
# This file contains the base and custom revision numbers.
# Needs to be checked out and updated during the nightly
# build process.
build.rev = 1332
custom.rev = 1285

Very simple file. The line that needs to replaced is being replaced with an environment variable that is the 2-digit year plus Julian date, with the leading zero stripped, e.g., 01 + 332 = 1332.

I tried each command listed and got command cannot be parsed for two of them.
Basically, I do not know the entire line value in the file prior to the build process. If I did, I could use the 's' and substitute, but I used 'c\' to change instead. I need to grab the line that starts with /build.rev/ and replace the entire line with this:
build.rev = $NEW_BUILD_ID
Hope this helps.

--
Shane
Shane Coombs
Occasional Contributor

Re: sed command cannot be parsed

OK, after adding the line feed, it executes, but it still isn't placing the new BUILD_ID in the new file. It retained the old value from the file. So it basically copied the file into another file. However, I may be able to make it work from there. Any more suggestions are gladly welcomed, guys. And thanks.
--
Shane
Shane Coombs
Occasional Contributor

Re: sed command cannot be parsed

Someone had set the environment variable to the same value in the file! So it did work once the line feed was added. Wierd that Solaris seems to inject the line feed, and Gnu sed on Linux had no trouble, but I will verify both of those are identical to this situation. Thanks for the help, guys.
Problem solved, monkey off back, smile on face...
--
Shane