1834643 Members
3427 Online
110069 Solutions
New Discussion

Re: vi

 
shruti_1
Advisor

vi

hI i have a file which is approx 100 mb in size. editing its is a complicated task. Actually I wanted to know is there any method by which first 10 lines of this file can be deleted without opening the file
11 REPLIES 11
Peter Godron
Honored Contributor

Re: vi

Arunvijai_4
Honored Contributor

Re: vi

Hi Shruti,

You can easily do with "sed"

# sed '1,10d'

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Peter Godron
Honored Contributor

Re: vi

shruti_1
Advisor

Re: vi

what is the meaning of '1,10d' and if i need to deleted the lines from end then what do i need to give
Chauhan Amit
Respected Contributor

Re: vi

Hi Shruti,

# delete the last 10 lines of a file
sed -e :a -e '$d;N;2,10ba' -e 'P;D' # method 1
sed -n -e :a -e '1,10!{P;N;D;};N;ba' # method 2


-Amit
PS: Don't forget to assign points to the answers.
If you are not a part of solution , then you are a part of problem
Raj D.
Honored Contributor

Re: vi

Shruti ,

sed '1,10d' means it will delete lines from 1 to 10.

and redirect the output to a different file , that will be your target file.



Also here is a sed FAQ that may help to understand further:

http://www.faqs.org/faqs/editor-faq/sed/

Cheers,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
Raj D.
Honored Contributor

Re: vi

Shruti ,

Here is your profile :

I have assigned points to 0 of 15 responses to my questions.

Try to make it 15 of 15 and make your forum profile better. Remeber to assign points to them , who are trying to help you.


hth,
Raj.


( * 0 point please. )
" If u think u can , If u think u cannot , - You are always Right . "
Arturo Galbiati
Esteemed Contributor

Re: vi

Hi,
this perl one-liner command will delete the first 10 lines in 'file' saving in the meanwhile the 'file' as 'file.old':

perl -i.old -ne 'print unless 1 .. 10' file

HTH,
Art

N.B. Please assign points!
Steve Post
Trusted Contributor

Re: vi

It's really simple. A user called "shruti" puts in a question. But apparently they do NOT want an answer to it. If they did, they would say something like "thanks." or perhaps assign points to the response.

And any other user that looks at the responses does not know which one is good, and which one is bad. Why? Because all of the points are unassigned.
HGN
Honored Contributor

Re: vi

HI

I agre with Steve please spend their valuable time helping out and the best way to show the appreciation would be to assign points.

0 out of 18

Rgds

HGN
HGN
Honored Contributor

Re: vi

HI

I agre with Steve please spend their valuable time helping out and the best way to show the appreciation would be to assign points.

If this issue is resolved you can assign points and close this thread

0 out of 18

Rgds

HGN