C
C
copyerfiled2017-02-21 23:52:02
bash
copyerfiled, 2017-02-21 23:52:02

How to remove a line from a file above or below a searched value?

The command deletes the line with the value (pattern)
sed '/pattern/d' file.txt
How to delete the line above and below the line with the given value, but leave the searched line intact? (in separate commands)
Maybe some other utility is needed?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Saboteur, 2017-02-21
@copyerfiled

Try to reverse the text and remove the line below
tac file.txt | sed '/pattern/{n;d;}' | tac

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question