in reply to grep and delete
You can, but these simpler tasks are easier to do with an editor unless the file is very large:
Alternately replace ed with ex, the same command will work with it.ed file <<<$'/\<word\>/+,$d\nw'
Update: Sure, you can do it with truncate too, like
perl -we 'open $F, "+<", $ARGV[0] or die; while (<$F>) { /\bword\b/ an +d truncate $F, tell $F; }' file
Using an external grep program might also be possible, but beware that this command below truncates before the line containing the word. (I only include it because this is the first use I've found for the bash <> redirection operator. perl -we 'length($n = `grep -wbm1 word`) and truncate STDIN, $n;' <>file
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: grep and delete
by Anonymous Monk on Jan 21, 2006 at 14:54 UTC |