Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to remove a specific line from a file
based on a user defined input. I had found a
similar situation where sed was used, but when I
tried using it in my script, sed had trouble with the
variable input, but would work fine if I put in a
number within the text editor. Any suggestions on
how I might be able to get this to work?

If you include a variable, the sed command needs to be surrounded with double, not single quotes
HOME=/usr/home/bob
sed -e "s/${HOME}/replacement_string/" filename
sed -e "#~^.*${HOME}.*#d" filename
The -v flag to grep says to print all lines except those contianing that string
grep -v $HOME filename
will print all lines except those containing /usr/home/bob
If this doesn't help, please post what you have and someone can help you fix it.

Thanks for the help... I'm teaching myself shell
scripting, so I still had a little trouble with sed, but
I'm sure its because of my lack of expeirience. I
did mange to get my script to work exactly as I
wanted tho... heres how.The script first displays several lines from a file
and numbers them, then asks which line should
be deleted....read NUMBER
DELETE=`tail +$NUMBER file | head -1`
grep -v $DELETE file > file1
mv file1 fileI'm not sure if this is the most efficient way to get
the job done, but it works fine for my needs. I'm
always open to suggestions for better methods, as
I'm just doing this for the sake of learning.

One more little speed bump...
this script worked fine in a test, but when I applied
it towards my actual script, I came across a
problem, which I'm sure is something simple, but
could not stumble across on my own.
This is for an invoice program for myself.... the file
contains lines that include...
MM/DD/YY Dollar amount Client
the spaces are tripping up my grep -v command.
The line is called as a variable...
grep -v $DELETE file > file1
I tried single and double quotes around the
$DELETE variable, but it still get...grep: Money: No such file or directory
grep: Clent: No such file or directoryI just need to know how to get grep to see the
variable as a single statement

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |