The UNIX and Linux Forums  

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


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression rag84dec Linux 2 05-29-2008 01:05 AM
#!/bin/sh script fails at StringA | tr "[x]" "[y]" by_tg UNIX for Dummies Questions & Answers 3 02-22-2008 08:17 AM
Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" Lokesha UNIX for Dummies Questions & Answers 4 12-19-2007 09:52 PM
Shell Script fails with "can't connect to client" sseenu79 HP-UX 2 12-20-2006 06:47 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-14-2005
Junior Member
 

Join Date: Dec 2005
Location: Windsor, Ont Canada
Posts: 13
"sed -n expression " fails. Why?

Hi Everyone!

I am trying to extract records between date makers in a log file. My selection string doesn't work, though. Please help.

This test works, if I manually enter the two date-strings (output=28 lines):
Code:
# sed -n '/\[20051213\]/,/\[20051214\]/p' ./access_log
But if the date string is a variable, it will not work:
eg1 (output=ZERO lines):
Code:
# DF="20051213"; DT="20051214"; export DF DT
# sed -n '/\[`echo ${DF}`\]/,/\[`echo ${DT}`\]/p' ./access_log
eg2, using --file= (output= sed error message):
Code:
# DF="20051213"; DT="20051214"; export DF DT
# echo "'/\[${DF}\]/,/\[${DT}\]/'" > /tmp/sed_file
# cat /tmp/sed_file
# '/\[20051213\]/,/\[20051214\]/'  ## note: contents of /tmp/sed_file
# sed -n --file=/tmp/sed_file ./tangofreaks_access_log
# sed: file /tmp/sed_file line 1: Unknown command: `''
What is going wrong??? ???
Please help! Thanks
GrahamB

Last edited by grahamb; 12-14-2005 at 04:31 AM. Reason: Clearer view of "CODE"
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 12-14-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
and this? - no need for 'echo':
Code:
DF="20051213"; DT="20051214"; sed -n "/\[${DF}\]/,/\[${DT}\]/p" ./access_log
Reply With Quote
  #3 (permalink)  
Old 12-14-2005
Junior Member
 

Join Date: Dec 2005
Location: Windsor, Ont Canada
Posts: 13
Thumbs up Solved!

Thanks vgersh99 !
I would never have dreamt to use the sed string with out the single quotes. Well it worked;

thank you
GrahamB
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0