From owner-freebsd-questions@FreeBSD.ORG Thu Jun 21 19:12:10 2012 Return-Path: Delivered-To: questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CE460106566B for ; Thu, 21 Jun 2012 19:12:10 +0000 (UTC) (envelope-from cyberleo@cyberleo.net) Received: from paka.cyberleo.net (paka.cyberleo.net [66.219.31.21]) by mx1.freebsd.org (Postfix) with ESMTP id 9A3C98FC12 for ; Thu, 21 Jun 2012 19:12:10 +0000 (UTC) Received: from [172.16.44.4] (den.cyberleo.net [216.80.73.130]) by paka.cyberleo.net (Postfix) with ESMTPSA id 674D429652; Thu, 21 Jun 2012 15:12:04 -0400 (EDT) Message-ID: <4FE37203.3020404@cyberleo.net> Date: Thu, 21 Jun 2012 14:12:03 -0500 From: CyberLeo Kitsana User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.4) Gecko/20120617 Thunderbird/10.0.4 MIME-Version: 1.0 To: Odhiambo Washington References: In-Reply-To: X-Enigmail-Version: 1.3.5 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: questions Subject: Re: A bash scripting question X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 21 Jun 2012 19:12:11 -0000 On 06/21/2012 08:40 AM, Odhiambo Washington wrote: > How Can I simplify/perfect the following script, so that I read _ALL_ the > lines in the file and act on the content as shown below, so that I do not > have to specifiy an action per line? > > This below is doing exactly what i need BUT reading one line at a time > untill the 10th line, if i want more i add manually... > This might help some1 someday! But if there is a way to perfect it please > do so..... > > #!/usr/local/bin/bash > > smsfile=email_to_sms > `grep Subject /var/spool/mail/sms >>$smsfile` > if [[ -s $smsfile ]] ; then > cat /dev/null > /var/spool/mail/sms > sed -i 's/Subject: //g' $smsfile > echo `sed -n '1p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==1 > {print $1}' $smsfile` > echo `sed -n '2p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==2 > {print $1}' $smsfile` > echo `sed -n '3p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==3 > {print $1}' $smsfile` > echo `sed -n '4p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==4 > {print $1}' $smsfile` > echo `sed -n '5p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==5 > {print $1}' $smsfile` > echo `sed -n '6p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==6 > {print $1}' $smsfile` > echo `sed -n '7p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==7 > {print $1}' $smsfile` > echo `sed -n '8p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==8 > {print $1}' $smsfile` > echo `sed -n '9p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==9 > {print $1}' $smsfile` > echo `sed -n '10p' $smsfile` | /usr/bin/gammu --sendsms TEXT `awk 'NR==10 > {print $1}' $smsfile` > else > echo "***********Sorry the SMS FILE "$smsfile" is empty.************" > fi > gammu-smsd start > cat email_to_sms >> email_to_sms2 > cat /dev/null > email_to_sms Off the top of my head: ----8<---- #!/bin/sh -e sed -e '/^Subject: /!d; s/^Subject: //' /var/spool/mail/sms > "${smsfile}" :>/var/spool/mail/sms xargs -L1 /usr/bin/gammu --sendsms TEXT < "${smsfile}" mv -f "${smsfile}" "${smsfile}.bak" ----8<---- No loops necessary. By the way, what's gammu, and why is it in /usr/bin ? -- Fuzzy love, -CyberLeo Technical Administrator CyberLeo.Net Webhosting http://www.CyberLeo.Net Furry Peace! - http://wwww.fur.com/peace/