The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #2 (permalink)  
Old 03-18-2008
era
Guest
  
 

Posts: n/a
Bits: 0 [Banking]
man grep


Code:
read input
fgrep -vx "$input" file

It removes the line completely, and doesn't even leave the newline. If you require the newline to be preserved, it's a bit harder.

It's not too tough to generate a proper regular expression, per se, but it tends to be a bit ugly.


Code:
read input
echo "$input" | sed -e 's/[][\\.*^$]/\\&/g; s/.*/s%^&\$%%/' | sed -f - file

This is untested, and intended merely as a proof of concept. I probably forgot one or two special characters which need to be backslash-escaped. (Hint: remove the final part of the pipeline to see the generated script.)