1. sed problem: using sed in a shell script
I am having a very odd problem. The following command is not working
in my shell script:
#!/bin/sh
# snip code #
sed "$start_line,$end_line""d" $1.tmp > $1.new
# END snip #
But, it _does_ work if i enter it at the command-line:
[eve]$ set start_line=2 ; set end_line=4 ; \
sed "$start_line,$end_line""d" tokenize_line.c.tmp > tokenize_line.c.new
This works on the command-line, but not in the script as well:
[eve]$ set start_line=2 ; set end_line=4 ; \
sed "$start_line,${end_line}d" tokenize_line.c.tmp > tokenize_line.c.new
then odd part is that if i set the variables in the script manually,
everything works ok:
#!/bin/sh
# snip #
startline=2; endline=4
sed "$start_line,$end_line""d" $1.tmp > $1.new
# END snip #
so i figured.. there must be space or something before/after the
numbers in the variables. but that is disproved, because i tried this
in the original shell script right before calling sed:
#snip
echo "cutting lines foo${start_line}foo to foo${end_line}foo"
#end snip
and that outputs this (no spaces!):
$
cutting lines foo2foo to foo4foo
so basically, i need to cut line ranges from files, and sed is the
only way i know how to do it, and it dont work (when interpolating
variables) in the shell script. any ideas here? (oh.. my shell is
tcsh)
--
MGatto
Support the anti-spam movement; see <http://www.cauce.org/>
2. What's up with the ports?!?
3. . sed script unix shell script ispell
4. GNOME TASK BAR
5. . sed script offered, sed script wanted
6. Starting point for new user?
7. Pointers/Help with a basic shell script (Shell Newbie alert)
8. How do I get rid of mouse?
9. Newbie help with Shell scripts (using Korn shell)
10. NEWBIE-Shell scripting - When to use script variable vs. create tmp file???
11. sed works in shell, but not in a script
12. Bourne shell CGI script and sed
13. shell script and sed