Hi I'm trying to select text between two lines, I'm using sed to to this, but I need to pass variables to it. For example
start="BEGIN /home/mavkoup/data"
end="END"
sed -n -e '/${start}/,/${end}/g' doesn't work. I've tried double quotes as well. I think there's a problem with the / in the pathname. I've also tried using sed to replace them with \/ but I can't get that to work either.
I never got the hang of awk, and I can't get that command to work lol. I'll keep working on it.
---------- Post updated at 10:37 AM ---------- Previous update was at 09:36 AM ----------
Arg I'm annoyed. Here's my actual code:
Some process sets $var to:
var="/home/mavkoup/data"
start_f="BEGIN_FILE_INFO `echo ${var}`"
cat input.txt | sed -n -e "/${start_f}/,/END_FILE_INFO/p" > output.txt
I get the error sed: command garbled: /BEGIN_FILE_INFO /home/mavkoup/data/,/END/p
If instead I use
var="BEGIN_FILE_INFO" the code runs fine.
---------- Post updated at 10:53 AM ---------- Previous update was at 10:37 AM ----------
FYI I got it. Needed to figure out how to replace the / with \/ in the path. s/\//\\\//g wouldn't work, needed it to be s:\/:\\\/:g and then everything was good again!