sed unterminated `s' command?

Hi there,

I'm pretty new to this whole scripting thing. I've written myself something which takes my txt file of SMSes (the backup from the phone), and puts them into an email format, saving them as .eml files. I've tested and uploaded a batch to gmail, but because of threading issues, I've decided that I need to individualise the subject lines so that they display better. For reference, here's the code..

My problem is such - I've added the following three lines to the code, and now I'm getting an "unterminated `s' command" no matter what I try...

Basically what I want to do is to take the 1st line of the .eml file, (the from: line), and the second line of the file (the to: line) and add them into the subject: line to individualise each one.

The code I tried was

But I can't see where I've gone wrong? Any ideas?

Hello, donnacha, and welcome to the forums.

For starters, your variable names don't match up (from1 vs from, to1 vs to), although I don't think that's the source of the problem (perhaps that's just a typo in the post). I suspect that the problem is that the values of the from1 and to1 variables will contain multiple lines if there are multiple files that match the *eml pattern. The embedded newlines are almost certainly what is causing the problem with the sed command.

Perhaps something akin to the following will suit your needs:

for f in *eml; do
    sed -i "s/SMS/SMS $(head -n1 "$f") to $(sed -n '2p' "$f")/g" "$f"
done

Regards,
Alister