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?

Community
  • 1
  • 1
Bubnoff
  • 3,917
  • 3
  • 30
  • 33

1 Answers1

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
kev
  • 155,172
  • 47
  • 273
  • 272
  • I believe that's the issue ...though it's actually a name field eg.,. These are massive files --- is there a way to – Bubnoff Jan 12 '12 at 02:09
  • As I was saying --- is there a way to quote around this? – Bubnoff Jan 12 '12 at 02:22
  • 2
    I see two articles that talk about stripping white space from a variable (which may help you): [article 1](http://stackoverflow.com/questions/369758/how-to-trim-whitespace-from-bash-variable) and [article 2](http://stackoverflow.com/questions/324167/remove-whitespace-from-bash-variable). Are these replacement variables read in from some file? If so, article 1 might be what you want. – Jonah Bishop Jan 12 '12 at 03:02
  • @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! – Bubnoff Jan 12 '12 at 03:54