Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-09-2012
Registered User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
pass parameter to SED

My script(ksh) works fine for
---------------------------------------------------

Code:
sed -n '28,31p' ${l_name} >> ${LOG_DIR}/Email.txt

---------------------------------------------------
But I wand to pass parrmeter to this syntax

I did the following things
---------------------------------------------------

Code:
 grep -n '^bad' ${l_name}|read lstart 
 grep -n '^Statistics' ${l_name}|read lend

---------------------------------------------------

lstart will give me 28 and lend will 31 . Now How I will pass it sed.
below code doesnt work
---------------------------------------------------

Code:
sed -n '$lstart,${lend}p' ${l_name} >> ${LOG_DIR}/Email.txt

---------------------------------------------------
Pease suggest me .

Last edited by Scrutinizer; 10-09-2012 at 01:41 PM.. Reason: code tags
Sponsored Links
    #2  
Old 10-09-2012
spacebar's Avatar
Registered User
 
Join Date: Oct 2009
Location: spaceBAR Central
Posts: 299
Thanks: 0
Thanked 58 Times in 58 Posts
Try it with double quotes(") so that the shell will expand the variable:

Code:
sed -n "${lstart},${lend}p" ${l_name} >> ${LOG_DIR}/Email.txt

Sponsored Links
    #3  
Old 10-09-2012
Lem Lem is offline
Registered User
 
Join Date: Jun 2012
Location: Lombardia, Italy
Posts: 179
Thanks: 5
Thanked 38 Times in 38 Posts
Quote:
Originally Posted by deep_kol View Post
Code:
sed -n '$lstart,${lend}p' ${l_name} >> ${LOG_DIR}/Email.txt

Single quotes prevent parameter expansion. Use double quotes instead.
--
Bye
    #4  
Old 10-09-2012
elixir_sinari's Avatar
Gotham Knight
 
Join Date: Mar 2012
Location: India
Posts: 1,370
Thanks: 87
Thanked 476 Times in 456 Posts
What are you actually trying to accomplish with the 2 grep commands? There might be better ways.
Sponsored Links
    #5  
Old 10-09-2012
Registered User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Double quote also didnt work

There is a log file i want to capture the portion between line 28 and 31 .

Code:
f_email()
{
  message "Sending  Bad record details  through Email "
  
  f_name=`ls -ltr ${BAD_FILE1} 2>/dev/null|awk '{print $9}'`
  l_name=`ls -ltr ${LOG_FILE1} 2>/dev/null|awk '{print $9}'`

  grep -n '^bad' ${l_name}|read lstart 
  grep -n '^Statistics' ${l_name}|read lend

echo "Please find the below reason for the rejection . To check the bad data plase find the attachment\n" > ${LOG_DIR}/Email.txt

#sed -n '28,31p' ${l_name} >> ${LOG_DIR}/Email.txt
sed -n "${lstart},${lend}p" ${l_name} >> ${LOG_DIR}/Email.txt

if [[ -s $f_name ]] then
    (cat ${LOG_DIR}/Email.txt;uuencode $f_name $f_name)|mailx -s "MFP SIZE Exceed report error" BalB@dressbarn.com
fi
}

Sponsored Links
    #6  
Old 10-09-2012
joeyg's Avatar
joeyg joeyg is online now Forum Staff  
modérateur
 
Join Date: Dec 2007
Location: Out running a Marathon.
Posts: 2,192
Thanks: 48
Thanked 127 Times in 119 Posts
Why not...


Code:
head -31 sample.txt | tail -4

will give you the four lines 28-29-30-31 from your file.
Sponsored Links
    #7  
Old 10-09-2012
Registered User
 
Join Date: Jun 2007
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
joeyg,
how to pass this 31 and 4 dynamically . these nos are not fix .
it may be 26 and 10
Sponsored Links
Closed Thread

Tags
sed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to pass the parameter value to a... ? khestoi UNIX for Dummies Questions & Answers 5 02-15-2011 12:59 PM
How to pass parameter to subroutine ssuresh1999 UNIX for Dummies Questions & Answers 2 08-15-2008 05:04 PM
How to pass a parameter megh Shell Programming and Scripting 1 07-18-2008 02:39 AM
PASS parameter to AWK unisam UNIX for Dummies Questions & Answers 2 05-14-2004 09:51 AM



All times are GMT -4. The time now is 10:02 AM.