"sed -n expression " fails. Why?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting "sed -n expression " fails. Why?
# 1  
Old 12-14-2005
"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??? Smilie ???
Please help! Thanks Smilie
GrahamB

Last edited by grahamb; 12-14-2005 at 08:31 AM.. Reason: Clearer view of "CODE"
# 2  
Old 12-14-2005
and this? - no need for 'echo':
Code:
DF="20051213"; DT="20051214"; sed -n "/\[${DF}\]/,/\[${DT}\]/p" ./access_log

# 3  
Old 12-14-2005
MySQL Solved!

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

thank you Smilie
GrahamB
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Awk,sed : change every 2nd field ":" to "|"

Hi Experts, I have a string with colon delimited, want 2nd colon to be changed to a pipe. data: 101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3: I am trying with sed, but can change only 1 occurance: echo "101:8:43:4:72:14:41:69:85:3:137:4:3:0:4:0:9:3:0:3:12:3:" | sed 's/:/|/2'... (5 Replies)
Discussion started by: rveri
5 Replies

2. 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

3. Shell Programming and Scripting

how to use "cut" or "awk" or "sed" to remove a string

logs: "/home/abc/public_html/index.php" "/home/abc/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" "/home/xyz/public_html/index.php" how to use "cut" or "awk" or "sed" to get the following result: abc abc xyz xyz xyz (8 Replies)
Discussion started by: timmywong
8 Replies

4. Shell Programming and Scripting

why "aab" matchs "ab" when using reglar expression ?

Please see the following code, why "aab" matchs "ab" when using reglar expression ? $ ] && echo "ok" || echo "error"; ok $ ] && echo "ok" || echo "error"; error $ ] && echo "ok" || echo "error"; error $ ] && echo... (8 Replies)
Discussion started by: 915086731
8 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Simplify Bash Script Using "sed" Or "awk"

Input file: 2 aux003.net3.com error12 6 awn0117.net1.com error13 84 aux008 error14 29 aux001.ha.ux.isd.com error12 209 aux002.vm.ux.isd.com error34 21 alx0027.vm.net2.com error12 227 dux001.net5.com error123 22 us008.dot.net2.com error121 13 us009.net2.com error129Expected Output: 2... (4 Replies)
Discussion started by: sQew
4 Replies

7. Shell Programming and Scripting

cshell integer expression from "0000" to "1999"

I have 2000 files named like "file-fr0000.log", "file-fr1999.log"... I wanna generate the file names automatically in the following c shell script: set fr = 0 while ($fr <= 1999) grep "ENERGY" file-fr$fr.log > data.dat @ fr = ( $fr + 1 ) end The above will generate file names... (3 Replies)
Discussion started by: rockytodd
3 Replies

8. Shell Programming and Scripting

cat $como_file | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g'

hi All, cat file_name | awk /^~/'{print $1","$2","$3","$4}' | sed -e 's/~//g' Can this be done by using sed or awk alone (4 Replies)
Discussion started by: harshakusam
4 Replies

9. Linux

Regular expression to extract "y" from "abc/x.y.z" .... i need regular expression

Regular expression to extract "y" from "abc/x.y.z" (2 Replies)
Discussion started by: rag84dec
2 Replies

10. UNIX for Dummies Questions & Answers

#!/bin/sh script fails at StringA | tr "[x]" "[y]"

I need to take a string (stringA) check it for spaces and replace any spaces found with an equal (=) sign. This is not working. There are spaces between each component: $StringA | tr "" "" The error returned is: test: Specify a parameter with this command Can you help? (3 Replies)
Discussion started by: by_tg
3 Replies
Login or Register to Ask a Question