?
Solved

shell script to delete 100 lines and save as same filename in Linux

Posted on 2010-01-12
7
Medium Priority
?
335 Views
Last Modified: 2013-12-06
Hi, I want to have a shell script to edit and delete 100 lines everyday and as same filename, this is something like:

vi del100.log
100 dd
:wq

P.S: This log file is active all the time and lock by the application, but no problem to delete 100 lines by manually.
0
Comment
Question by:silterra
  • 3
  • 2
  • 2
7 Comments
 
LVL 16

Expert Comment

by:Peter Kwan
ID: 26291429
You may perform this:

tail +101 del100.log | tee del100.log
0
 
LVL 10

Assisted Solution

by:Martin_J_Parker
Martin_J_Parker earned 300 total points
ID: 26293420
or you can use the vi commands via the stream editor, sed.
With sed you don't need the colon:
cat del100.log | sed -e "1,100d" > del100.log
0
 

Author Comment

by:silterra
ID: 26299817
Hi pkwan, Martin, there is some mis-understanding, in fact what I want is using vim to run, see below:

vim '+1,100dd' '+wq' del100.log

I failed to delete first 100 lines, what was wrong my script??
0
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

 
LVL 16

Expert Comment

by:Peter Kwan
ID: 26301329
I think vim does not recognize "+1,100dd" as a valid command.

You may try if the following works:

vim '+d100' '+wq'  test.txt
0
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 1200 total points
ID: 26301339
Sorry, should be:

vim '+d100' '+wq'  del100.log
0
 

Author Closing Comment

by:silterra
ID: 31675979
Thank
0
 
LVL 10

Expert Comment

by:Martin_J_Parker
ID: 26301608
Looks like you have the numbers and the d in the wrong place.
It should be:
vim  '+1,100d'  '+wq'  del100.log
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating a Samba server for a small office. Ubuntu Linux and Samba can breathe new life into a retired PC and save an office money on new hardware/software. Our example server will have two hard disks, one exclusively for storing shared data. …
In my business, I use the LTS (Long Term Support) versions of Linux. My workstations do real work, and so I rarely have the patience to deal with silly problems caused by an upgraded kernel that had experimental software on it to begin with from a r…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Free Data Recovery software is an advanced solution from Kernel Tools to recover data and files such as documents, emails, database, media and pictures, etc. It supports recovery from physical & logical drive after a hard disk crash, accidental/inte…

593 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question