sed & awk--get section of file based 2 params

I need to get a section of a file based on 2 params. I want the part of the file between param 1 & 2. I have tried a bunch of ways and just can't seem to get it right. Can someone please help me out.....its much appreciated. Here is what I have found that looks like what I want....but doesn't give me back the right stuff.

sed -n '/[$PARAM1]/,/[$PARAM2]/p'

try using DOUBLE-quotes.
also posting a sample file and a desired output would hellp as well.

is that it can't read the $Param passed in. When I put some text instead of the param it does it fine. One problem I have is the param will have slashes in it (the param is a full path filename). Does anyone know how to get it to read the param with slashes in it. Here is what it will look like...

sed -n '/$PARAM1/,/$PARAM2/p'

With the params uncovered it is

sed -n '//directory/filename/,//directory/filename2/p'

I've noticed previously - use DOUBLE-quotes.
Also....


sed -n "#${PARAM1}#,#${PARAM2}#p"

Hi,

Try putting double quotes around the command and single quotes around the PARAM

sed -n "/'$PARAM1'/,/'$PARAM2'/p"

or if you are putting it in the other format then you can just use the backslash to tell the script to treat the forward slash as a character and not an argument like

sed -n '/\/directory\/filename/,/\/directory\/filename2/p'

Hope this helps.

Paulo.

I have tried the suggestions you guys gave and it looks like they are close but not quite right. If I put them in double quotes it says its garbled. It does recognize the params but just can't handle them. I also switched / to # sign and put brackets around param and doesn't come back with anything.

Here is what I did

sed -n "/'$FILENAME'/,/'$FILENAME2'/p"`

Out is below:

sed: command garbled: /'/sybase_dumps/NXB_FDA_BACKUP/physdumps/reload_script_test20061130115518.dmp'/,/'/sybase_dumps/NXB_FDA_BACKUP/physdumps/reload_script_test20061201095324.dmp'/p

here's a sample script:

#!/bin/ksh

s='/abc/def'
e='/g/h/k'

sE=$(echo ${s} | sed 's#/#\\/#g')
eE=$(echo ${e} | sed 's#/#\\/#g')

echo "sE->[${sE}]"
sed -n "/${sE}/,/${eE}/p" myFile.txt

here's myFile.txt

/abc/def
asdkfjlaskfjd  asdlfj
as
df
asd
fa
sdf  asdfjaslkdfj asdflk
/g/h/k
asdfklj
asdfjk asdflkj asdf
asd
/abc/def
as;klfj a sdlkfj
asdfkljas alskfjd
/g/h/k
fasdklfj asdf

FILENAME="/sybase_dumps/NXB_FDA_BACKUP/physdumps/reload_script_test20061130115518.dmp"
FILENAME2="/sybase_dumps/NXB_FDA_BACKUP/physdumps/reload_script_test20061201095324.dmp"

sed -n "/'${FILENAME}'/,/'${FILENAME2}'/,p" /sybase_dumps/NXB_FDA_BACKU
P/control_files/reload_script_test

----I have also tried with no luck
sed -n "#'${FILENAME}'#,#'${FILENAME2}'#,p"

sed -n "#'${FILENAME}'#,#'${FILENAME2}'#,p"

sed -n "#${FILENAME}#,#${FILENAME2}#,p"

sed -n "/'${FILENAME}'/,/'${FILENAME2}'/,p"

I think what others are trying to tell you is to not use single quotes at all. Single quotes prevent variable interpretation.

if anything works. Here are 2 more ways I have done it without success.

sed -n "/${FILENAME}/,/${FILENAME2}/,p"

and

sed -n "/$FILENAME/,/$FILENAME2/,p"

I get this error
First RE may not be null

What's with the comma before the "p"?

take a look at my last post - it should give you an idea of how to deal with the embedded '/' in your start/end addresses.

gave me what I needed. So I guess it must be because of the slash in the params?

Thanks for all your help everyone