Do you want to delete it because it's line 2, or because it's green?
Read up on the sed command.
For example
sed '2d' file > newfile
or
sed '/green/d' file > newfile
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Nothing works by editing the file 'in place', even your vi editor.
It's all write the new file, delete the old file, then rename. It's just vi hides those steps from you. On very rare occasions when something crashes, you'll see (and be glad of it) that the old file was preserved and the new file was broken.
Do the same thing in any script you write.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Be mindful of how the various shell quoting systems work.
Eg, try
sed '/'$choice'/d' file > newfile
But beware of users typing in a /
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
> Not all previous answers were exactly correct. You can edit a file in-place.
OK, show me.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
> You can pipe commands to ex(1) to edit a file 'in place'.
Like I said in my first post, the editors like ed, ex and vi merely hide the detail from you. There's still a write / delete / rename going on underneath.
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953