Skip to content
Advertisement

Remove lines are between two line numbers (or patterns) with sed [no duplicate]

I saw and read many topics about my problem, but they didn’t help me.

a close topic to my problem but it didn’t help me: removing lines between two patterns (not inclusive) with sed

Question: I have a text file and I want to remove lines are between two patterns.

note1: between these patterns, i don’t want to remove lines have a specific string as key-pattern.

pattern-1 can be a line number (line-2 >> this is static forever) or a word like as Speed (Also this word is static forever).

pattern-2 can be a line number (line-X >> this not static (it’s dynamic)) or a word like as Station MAC (if your solution based-on word, fortunately This is static((Station MAC))).

if your solution is based on line number, i wrote a AWK command to fetch line number for using in second pattern:

JavaScript

note2: according to note1, sed or other tools must not to remove line are contain my key-pattern.




Example: keeping lines have words Max or sms in themselves.

here, Max and sms are key-pattern.

Input: https://pastebin.com/cztQgm9m

JavaScript

Desired output: https://pastebin.com/gSv74mcZ

JavaScript

Advertisement

Answer

You can try this sed

Not perfect but with busybox on win7 !

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement