Lunartist
Lunartist

Reputation: 464

How to crop text after pattern in bash

If the text is

aaaa
bbbb
cccc
====
dddd

I want dddd as the result

If the text is

aaaa
====
bbbb
cccc
dddd

I want

bbbb
cccc
dddd

as the result.

I'm trying something like awk '{print $1}' | sed '/.*\n=*$/d' but it seems like sed can only delete a line.

Upvotes: 0

Views: 91

Answers (2)

Yuri Ginsburg
Yuri Ginsburg

Reputation: 2601

You can try something like

n=$(grep -n "^=*$" $1 | awk -F: '{print $1}')
let n+=1
tail +$n $1

Upvotes: 1

Beta
Beta

Reputation: 99134

You can indicate a range of lines, e.g. from line 1 to the line containing the pattern:

sed '1,/====/d'

Upvotes: 1

Related Questions