Link to home
Start Free TrialLog in
Avatar of silterra
silterraFlag for Malaysia

asked on

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

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.
Avatar of Peter Kwan
Peter Kwan
Flag of Hong Kong image

You may perform this:

tail +101 del100.log | tee del100.log
SOLUTION
Avatar of Martin_J_Parker
Martin_J_Parker
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of silterra

ASKER

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??
I think vim does not recognize "+1,100dd" as a valid command.

You may try if the following works:

vim '+d100' '+wq'  test.txt
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank
Looks like you have the numbers and the d in the wrong place.
It should be:
vim  '+1,100d'  '+wq'  del100.log