SED Problem
I have a file with that contains a list of names (
exactly 1 name per line. no spaces)
ie peter
(sed script to remove pete)
Part of my problem is that I can't figure out how to remove only pete (and not peter) I tried this
This works. Now I want to use a variable called name.
cat everyone.lis |sed -e '/^${name}$/ d' > everyone.lis This did not work. Any suggestions ?
I'm not near a unix system right now, so I can't test it out, but try placing quotes (single or double) around your variable: "$name"
The single quotes encapsulating your sed program prevents
the shell from evaluating variables before it executes it. Change those
to double-quotes, or in this case, you don't need any quotes.
And while you do not need braces around the variable in this case, it never hurts. You will not be able to redirect your output back to your input file. The first thing the shell will do, before it invokes sed, is to create an empty output file, and that will wipe out your input file before sed gets to process it. sed /^$name$/d everyone.lis > newfile
angle bracket testing ...
See Also
Have a Unix Problem
Unix Books :-
Return to : - Unix System Administration Hints and Tips (c) www.gotothings.com All material on this site is Copyright.
|