Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

sed unterminated `s' command?

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 05-04-2010
donnacha donnacha is offline
Registered User
Join Date: May 2010
Last Activity: 4 May 2010, 8:26 PM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
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..


sed -i 's/^$/newlinenewlinenewline \n /g' test2.txt #marks where breaks originally occured
#editing From/To headers below
sed -i 's/3538|+3538/08/g' test2.txt ##standardises number format from +3538/3538 to 08....
sed -i 's/From: My Phone/From: ###/g' test2.txt #makes default "me" sender my number
sed -i 's/To: My Phone/To: ####/g' test2.txt #""
sed -i 's/+3538/08/g' test2.txt
sed -i 's/3538/08/g' test2.txt

sed -i 's/From: 08/From: <08/g' test2.txt #adds the "<" character to the address string
sed -i 's/To: 08/To: <08/g' test2.txt #adds the "<" character to the address string
sed -i '/From:/s|$|>|' test2.txt #adds the last ">" to the address string
sed -i '/To:/s|$|>|' test2.txt #adds the last ">" to the address string

#editing Date headers
sed -i 's/Received:.*\09//g' test2.txt
sed -i 's/Received:.*\0//g' test2.txt
sed -i 's/Sent: /Subject: SMS \nDate: /g' test2.txt

sed -i '/^$/d' test2.txt #deletes blank lines from previous removal of dates
sed -i 's/Text:/MIME-Version: 1.0 \nContent-Type: multipart\/alternative; \n boundary="----=_NextPart_000_000C_01CAE890.FD6A3090" \nX-Priority: 3 \nX-MSMail-Priority: Normal \nX-Unsent: 1 \nX-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 \n \nThis is a multi-part message in MIME format. \n \n------=_NextPart_000_000C_01CAE890.FD6A3090 \nContent-Type: text\/plain; \n charset="iso-8859-1" \nContent-Transfer-Encoding: quoted-printable \n \n------=_NextPart_000_000C_01CAE890.FD6A3090 \nContent-Type: text\/html; \n charset="iso-8859-1" \nContent-Transfer-Encoding: quoted-printable \n \n<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.0 Transitional\/\/EN"> \n<HTML><HEAD> \n<META http-equiv=3DContent-Type content=3D"text\/html; = \ncharset=3Diso-8859-1"> \n<META content=3D"MSHTML 6.00.2900.5945" name=3DGENERATOR> \n<STYLE><\/STYLE> \n<\/HEAD> \n<BODY bgColor=3D#ffffff> \n<DIV><FONT face=3DArial size=3D2>/g' test2.txt

sed -i 's/newlinenewlinenewline/<\/FONT><\/DIV><\/BODY><\/HTML>\n \n------=_NextPart_000_000C_01CAE890.FD6A3090--/g' test2.txt #returns breaks

sed -i 's/[ \t]*$//' test2.txt #removes whitespace, email errors otherwise.
awk '/From: /{n++}{print >"out" n ".eml" }' test2.txt #creates .eml files
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

from1=$(head -n1 *eml)
to1=$(sed -n '2p' *eml)
sed -i "s/SMS/SMS $from to $to/g" *eml
But I can't see where I've gone wrong? Any ideas?
Sponsored Links
Old Unix and Linux 05-04-2010
alister alister is offline
Registered User
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 976 Times in 790 Posts
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"

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Using SED command in a shell script: Unterminated address regex Alpha3363 Shell Programming and Scripting 7 03-10-2010 06:02 AM
Syntax error: Unterminated quoted string evilSerph Shell Programming and Scripting 5 03-13-2009 03:01 PM
awk/sed Command : Parse parameter file / send the lines to the ksh export command rajan_san Shell Programming and Scripting 4 11-06-2008 12:29 PM
Unterminated string dr46014 UNIX for Dummies Questions & Answers 3 08-23-2008 07:33 AM
assign a command line argument and a unix command to awk variables sweta_doshi Shell Programming and Scripting 0 08-08-2008 06:54 AM

All times are GMT -4. The time now is 09:51 AM.