1

This exact code was working in another script. I copied the function over and now it keeps giving the unterminated 's' command error.

sed "
        s@<%BRANCH-NAME%>@${_loc_name}@g
        s@<%BRANCH-ADDR%>@${_loc_strt}@g
        s@<%BRANCH-CTY%>@${_loc_city}@g
        s@<%CUST-NAME%>@${_pat_name}@g
        s@<%CUST-ADDR%>@${_pat_addr}@
        s@<%CUST-CTY%>@${_pat_city}@
        s@<%BARCODE%>@${_barcode}@g
        s@<%DATE%>@${_date}@
        s@<%TITLE%>@${_title}@
        s@<%AUTHOR%>@${_auth}@
        s@<%PRICE%>@${_price}@" "$_template" 

In response to requests for possible values:

These are huge files and this function is in a for loop. I use it to format forms for mailing. More info here: BASH: importing data from flat file into template

So this function worked for certain directories but I've hit a snag with this recent one.

I grepped for slash characters on the advice of kev below ...none found except '/'. Possibly 'silent' newlines.

find ./ -name "mail.TMP" -type f -exec grep -E '\n' {} \;

possible values would be things like:

${pat_name}

Hermann Hesse c/o His Mother

${loc_name}

Pandora SR home c/o Harmony City Hall

So ...maybe it's a quoting issue?

8
  • Do any of your ${_loc_name}, ${_loc_strt}, etc. variables contain an @ character? Commented Jan 11, 2012 at 22:04
  • Can you please paste your complete error? Commented Jan 11, 2012 at 22:10
  • Is this a sed script or are you using it inside regular bash script? If it is a sed script then you don't need sed and the quotes. If it is inside regular script then you need to add option -e. Commented Jan 11, 2012 at 22:16
  • 1
    @JaypalSingh: No, you don't need -e; sed s/this/that/ is equivalent to sed -e s/this/that/. (The -e option is probably necessary in some ambiguous cases, but this isn't one of them.) And the question title says it's a bash script. Commented Jan 11, 2012 at 22:59
  • @KeithThompson You're right!! Sorry about that. Then as you stated in the comments earlier, it could be that variable has @ which is throwing it off. Commented Jan 11, 2012 at 23:03

1 Answer 1

1
$ _loc_name=$'xxx\nyyy'
$ echo '<%BRANCH-NAME%>' | sed "s@<%BRANCH-NAME%>@${_loc_name}@g"
sed: -e expression #1, char 21: unterminated `s' command

Does any $var contain newline? Please echo them all to check.

$ echo "$_loc_name"
xxx
yyy
Sign up to request clarification or add additional context in comments.

4 Comments

I believe that's the issue ...though it's actually a name field eg.,. These are massive files --- is there a way to
As I was saying --- is there a way to quote around this?
I see two articles that talk about stripping white space from a variable (which may help you): article 1 and article 2. Are these replacement variables read in from some file? If so, article 1 might be what you want.
@JonahBishop - Dude, I think you're right about white space. I'm using the IFS to push this through a for loop -- specifically mentioned in the article you mention. Wil;l lokk at this more closely tomorrow. Thanks!

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.