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:

ed file <<<$'/\<word\>/+,$d\nw'
Alternately replace ed with ex, the same command will work with it.

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
    Hi everyone, WOW..!! I got so many replies.....I am trying to run the suggestions you gave...Now the problem I face is that...I am grepping an large xml file....(I dont have any hassles with memory ..) ..;-].....I have to grep for a word in the tail end of the file and remove the line below that word. thank u kindly,