Sponsored Content
Top Forums Shell Programming and Scripting sed unterminated `s' command? Post 302418574 by donnacha on Tuesday 4th of May 2010 08:26:29 PM
Old 05-04-2010
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..

Quote:
#!/bin/bash

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

Quote:
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?
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Unterminated string

While running a shell script i am getting this warning but the script is working fine.while running the blocks of the scripts individually its running fine.But while pasting it combinedly this is the warning..wat may be the reason behind this and how to resolve it (3 Replies)
Discussion started by: dr46014
3 Replies

2. Shell Programming and Scripting

Using SED command in a shell script: Unterminated address regex

Hi All, I am trying to use a sed command in a shell script in order to delete some lines in a file and I got the following error message. I don't understand why it is not working 'cause I have tried with simple quotes, then with double-quotes, and it is not working. sed: -e expression #1,... (7 Replies)
Discussion started by: Alpha3363
7 Replies

3. Shell Programming and Scripting

[Solved] sed - query - unterminated suddenly

Hi, I have been trying to get various sed statements to work. I thought I had cracked it when suddenly I start recieving these messages "sed: -e expression #1, char 14: unterminated 's' command" It happens on any sed statement I now run. The only thing I have done inbetween trying to get... (0 Replies)
Discussion started by: mcclunyboy
0 Replies

4. Shell Programming and Scripting

Unterminated quoted string

Hello! I wroted a little script that should check for new updates on a server and get them if any. The problem is, every time I run it with sh, I'm getting an "script: 20: Syntax error: Unterminated quoted string" error! The problem is, there isn't any "unterminated quoted string" in my script:... (2 Replies)
Discussion started by: al0x
2 Replies

5. Shell Programming and Scripting

sed: -e expression #1, char 21: unterminated `s' command

I have read many threads, but I still didn't find the right answer. May be i didn't find the right thread, though are so many threads for the same question. Basically the situation is - find date in a file and replace it with another date. (its not homework, its part of lot of a big processing,... (10 Replies)
Discussion started by: avinthm
10 Replies

6. UNIX for Dummies Questions & Answers

sed error unterminated `s' command

I have list of data I have cut down to format: I am using sed command to remove the sed 's/ Returns error: sed: -e expression #1, char 5: unterminated `s' command Full code line is: cat textFile | cut -d ' ' -f 4 | cut ':' -f 1 | sed 's/ Thanks, Please use next time code tags... (2 Replies)
Discussion started by: maximus73
2 Replies

7. Shell Programming and Scripting

sed returns error "sed: -e expression #1, char 18: unterminated `s' command"

Hello All, I have something like below LDC100/rel/prod/libinactrl.a LAA2000/rel/prod/libinactrl.a I want to remove till first forward slash that is outputshould be as below rel/prod/libinactrl.a rel/prod/libinactrl.a How can I do that ??? (8 Replies)
Discussion started by: anand.shah
8 Replies

8. Shell Programming and Scripting

Sed: -e expression #1, char 16: unterminated address regex

I am trying to grep for a particular text (Do action on cell BL330) in a text file(sample.gz) which is searched in the content filtered by date+timestamp (2016-09-14 01:09:56,796 to 2016-09-15 04:10:29,719) on a remote machine and finally write the output into a output file on a local machine. ... (23 Replies)
Discussion started by: rbadveti
23 Replies

9. UNIX for Beginners Questions & Answers

Sed: -e expression #1, char 20: unterminated address regex

I am trying to add word in last of particular line. the same command syntex is running on prompt. but in bash script give error."sed: -e expression #1, char 20: unterminated address regex" Please help. for i in `cat servername`; do ssh -q -t root@$i sed -i '/simple_allow_groups =/s/$/,... (4 Replies)
Discussion started by: yash_message
4 Replies

10. UNIX for Beginners Questions & Answers

Unterminated <> operator

Hello. I'm self teaching myself and coded a program but I keep getting a illegal division by 0 error. I know what it means but I don't know where I am messing up. Here is the code: #!/usr/bin/perl @lines = <>; my %earned; my %possible; for ($i = 1; $i <... (6 Replies)
Discussion started by: Eric7giants
6 Replies
smsd(8) 							      Gnokii								   smsd(8)

NAME
smsd - daemon for handling incoming and outgoing SMSes using libgnokii SYNOPSIS
smsd [OPTIONS] DESCRIPTION
The SMSD (SMS daemon) program is intended for receiving and sending SMSes. The program is designed to use modules (plugins) to work with different backends. Currently are supported PostgreSQL, MySQL and a special module 'file' which is designed to work without an SQL database (see below for special instructions in the file module section). When SMSD uses an SQL server as a repository for SMSes you must create a database (default name is 'sms') with tables defined in sms.tables.{mod- ule}.sql files. Table 'inbox' is for received SMSes. SMSD periodically checks a given phone memory to move messages to this table. Only received SMSes and status reports are deleted from the phone, other kinds of messages are not removed. Table 'inbox' has the following fields: number phone number from which is sms received smsdate date set by SMS center insertdate date SMS was inserted into table text SMS text phone number of phone to use. If you use smsd without -t option you can ignore this column. See -t option below. processed smsd sets this always to FALSE. You can use it for another program which will parse SMSes. Table 'outbox' is for outgoing SMSes. SMSD periodically looks into this table and searches for lines with attribute 'processed' set to FALSE. If it finds such SMS, it will send SMS to 'number'. Table 'outbox' has the following fields: number recipient's phone number processed_date date of processing SMS. insertdate date of inserting SMS in table text SMS text phone number of phone to use. If you use smsd without -t option you must not fill this column. See -t option below. processed new SMS must have this attribute set to FALSE. SMSD will send this SMS and will update 'processed' to TRUE. error This attribute contains return value of gn_sms_send() function. For explanation of numeric values see <gnokii/error.h> in gnokii source. dreport request for delivery report per message. Possible values are 0 for no delivery report, 1 for delivery report. not_before sms will not be sent before this time (default 00:00:00). not_after sms will not be sent after this time (default 23:59:59). SMSD is multi threaded program. If you list processes you will see more than one instance of smsd. THE FILE MODULE This module doesn't need an SQL server to work. For incoming messages it works in a way that it calls a program giving phone number, date as parameter and the message text on stdin. In the smsd directory there is an example file action. It shows sms data to stdout. If you want something useful you must write your own action. For outgoing messages you can set spool directory where smsd looks regularly. Incoming sms are passed in format action number date < sms Outgoing sms must be in format: number text The name of file is unimportant but smsd ignores all files with prefix "ERR.". If smsd succesfully sends sms, it removes file from spool directory. If smsd cannot send sms prepends file with "ERR." prefix and ignores it. If you use -m file, -u (--user) and -c (--host) will have other meaning. -u is for action (action must be executable) -c is for spool directory where smsd looks for smses. Smsd must have read and write permissions to this directory. -p, -d parameters have no meaning when -m file is used. If you don't specify -u, default action is to print sms to stdout. If you don't specify -c, sms sending will be disabled. OPTIONS Available options: -u, --user db_username Specify user name. -p, --password db_password Specify user password. -d, --db db_name Specify database name for 'pq' and 'mysql' modules or full path to database file for 'sqlite' module (defaults to 'sms'). -c, --host db_hostname Specify database server host name. -s, --schema db_hostname Specify database schema used by the PostgreSQL module (defaults to 'public'). -m, --module db_module Specify which module to use for connection to DB server. Currently supported values are 'pq' for PostgreSQL, 'mysql' for MySQL, 'sqlite' for SQLite3 and 'file'. File module is not supported in Windows. -l, --libdir path_to_db_module Specify path to DB modules. If you specify pq module, smsd searches in libdir for file libsmsd_pq.so (for mysql - libsmsd_mysql.so). Do not interchange these plugins with default SQL libraries from database distribution! -f, --logfile file If used, smsd will monitor sms traffic to file "file". File is reopened and closed for every message so you can simply rename or delete it if you want to rotate logs. If you use '-' as filename smsd will use standard output. -t, --phone phone_number You can run more instances of smsd. One instance per phone. In this setup you must configure phone section in the config file. For example: [global] port = /dev/ttyS0 model = 6110 initlength = default connection = serial bindir = /usr/local/sbin/ use_locking = no serial_baudrate = 38400 smsc_timeout = 10 [phone_1] port = /dev/ttyS0 model = 6110 initlength = default connection = serial bindir = /usr/local/sbin/ use_locking = no serial_baudrate = 38400 [phone_2] port = /dev/ttyS1 model = AT initlength = default connection = serial bindir = /usr/local/sbin/ use_locking = no serial_baudrate = 38400 smsc_timeout = 10 In this setup if you run smsd without -t option it will use config from global section. If you run smsd with -t 1 it will use config from phone_1 and likewise with -t 2 uses phone_2. In case of use -t option smsd fills phone number for incoming sms's and in outbox it looks only for sms's with the specified phone number in column 'phone'. This behaviour gives you possibility to run one instance of smsd for every phone you have at the same time. -i, --interval interval Polling interval for incoming sms's in seconds. Default is 1 second. -S, --maxsms number When phone driver doesn't support sms status it is possible to specify number of sms's supported by phone. Default is 10. If driver support sms status this option is ignored. -b, --inbox memory_type Where to look for new messages (defaults to IN for most Nokia phones and to SM for all other phones). For debugging or for unusual setups you can use another memory type supported by your phone (eg. IN for the Inbox, OU for the Outbox, AR for the Archive, TE for the Templates and F1,...,F20 for your own folders). Use gnokii --showsmsfolderstatus for a list of such memory types. -0, --firstpos0 SMSD starts messages reading from position 1. If your phone stores sms's from postion 0, use this option. -v, --version Shows smsd version. -h, --help Shows short help. DIAGNOSTICS
Various error messages are printed to STDERR. Debug output can be enabled setting xdebug=on (for messages specific to SMSD) and debug=on (for messages specific to libgnokii) in the con- figuration file. BUGS
None reported. AUTHOR
SMSD was written by Jan Derfinak and contributed by other people. See also Docs/CREDITS from the Gnokii sources. COPYING
This program is distributed under the GNU Public License. SEE ALSO
gnokii(1) September 27, 2010 smsd(8)
All times are GMT -4. The time now is 01:41 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy