Home > Back-end >  How to crop text after pattern in bash
How to crop text after pattern in bash

Time:04-27

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.

CodePudding user response:

You can try something like

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

CodePudding user response:

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

sed '1,/====/d'
  • Related