|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
Quote:
-- Bye |
|
#4
|
||||
|
||||
|
What are you actually trying to accomplish with the 2 grep commands? There might be better ways.
|
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
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
|
||||
|
||||
|
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
|
|||
|
|||
|
joeyg,
how to pass this 31 and 4 dynamically . these nos are not fix . it may be 26 and 10 |
| Sponsored Links | ||
|
![]() |
| Tags |
| sed |
| Thread Tools | Search this Thread |
| 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 |
|
|