3

I'm trying to use sed to update some SQL commands, but getting unterminateds' command`

Command:

sed -i -f commands.sed mySql.sql

commands.sed

s;      if @ARI is not NULL
        begin
                exec spRun @Name='Txn', @NextValue=@Txn output
;       if @ARI is not NULL
        begin
                select @Txn= @Txn+ 1
;g

Do you know why?

Thanks for your time!

Jens
  • 69,818
  • 15
  • 125
  • 179
Pez Cuckow
  • 14,048
  • 16
  • 80
  • 130
  • possible duplicate of [Sed multiline replacement question](http://stackoverflow.com/questions/6350800/sed-multiline-replacement-question) –  Sep 05 '12 at 09:15
  • 1
    Im my opinion this is not a duplicate as it regards reading from a file which that question does not – Pez Cuckow Sep 05 '12 at 09:16

1 Answers1

5

sed works line-oriented. Your script contains newlines in patterns. So it complains about the first line,

s;      if @ARI is not NULL

which obviously is an unterminated substitution with s. You're probably better off using perl's regular expressions to deal with multiline substitutions in the spirit of

perl -0777 -ne 's/FROM\nLINE\n/TO\nTHIS\n/g;print'
Jens
  • 69,818
  • 15
  • 125
  • 179