?
Solved

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

Posted on 2010-01-12
7
Medium Priority
?
328 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order for businesses to be compliant with certain information security laws in some countries, you need to be able to prove that a user (which user it was becomes important to the business to take action against the user after an event has occurr…
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. …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

762 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