silterra
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.
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.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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??
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
You may try if the following works:
vim '+d100' '+wq' test.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank
Looks like you have the numbers and the d in the wrong place.
It should be:
vim '+1,100d' '+wq' del100.log
It should be:
vim '+1,100d' '+wq' del100.log
tail +101 del100.log | tee del100.log