Wednesday, April 27, 2022

[SOLVED] How to crop text after pattern in bash

Issue

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.


Solution

You can try something like

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


Answered By - Yuri Ginsburg
Answer Checked By - David Marino (WPSolving Volunteer)