0

The title says all. I tried several syntax, all failed. Maybe this is not possible with a single shoot... Of course, search engines didn't help, nor the manual that is difficult to understand, nor the info command. All lack an example with a range of "kind of" preselection

0

2 Answers 2

2

In the end I found this killer oneliner:

sed -i '1795,$ {/PaTtErN/d}' file.log 

be careful with the -i flag and read the manual before trying

1

Possible with AWK , too:

bash-4.3$ cat input.txt 
line one
and another line
running out of ideas for text
Oh, look , banana !
some more lines
this is boring
But what is not boring ? text processing !
bash-4.3$ awk 'NR<4; NR>4 && $0!~/banana/' input.txt 
line one
and another line
running out of ideas for text
some more lines
this is boring
But what is not boring ? text processing !

The idea here is to print all lines that are less than 4 untouched. Lines greater than 4 that do not contain specific pattern ( in this case the word "banana" ) , will be printed, and obviously those that do contain it won't be printed.

Not the answer you're looking for? Browse other questions tagged .