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
Asked
Active
Viewed 1,513 times
2 Answers
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

Sergiy Kolodyazhnyy
- 105,154
- 20
- 279
- 497

useful
- 1,834
- 4
- 25
- 32
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.

Sergiy Kolodyazhnyy
- 105,154
- 20
- 279
- 497