Operating System - Linux
1753925 Members
8918 Online
108810 Solutions
New Discussion юеВ

Re: Deleting lines till the end of a file from a particular position

 
SOLVED
Go to solution
Bejoy C Alias
Respected Contributor

Deleting lines till the end of a file from a particular position

Hi Guys,
My text file contains

abcv
adsa
egw
sg
##
str
dhd
dfh

I want to run a script which will delete the lines till the end of the file including the line ## . There should not be any user interaction for the script .
Be Always Joy ......
4 REPLIES 4
Hein van den Heuvel
Honored Contributor
Solution

Re: Deleting lines till the end of a file from a particular position


I assume you do not know the line value?
If you do then: awk '/^ab/,/^sg/' file
If you don't: awk '/^##/{done=1}{if (!done){print}}' file

Hein.

Vibhor Kumar Agarwal
Esteemed Contributor

Re: Deleting lines till the end of a file from a particular position

sed -e '1,/##/d' file
Vibhor Kumar Agarwal
Vibhor Kumar Agarwal
Esteemed Contributor

Re: Deleting lines till the end of a file from a particular position

Ooops I did just the opp.

sed -e '/##/,//d' file
Vibhor Kumar Agarwal
Bejoy C Alias
Respected Contributor

Re: Deleting lines till the end of a file from a particular position

Thanks For ur quick replys ....
I got the solution....
Be Always Joy ......