LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > dinakumar12
User Name
Password

Notices


Old

Simple script to delete last n lines

Posted 10-29-2013 at 10:53 AM by dinakumar12
Updated 12-31-2013 at 01:18 AM by dinakumar12

This may be possible using a single command but a very small and simple script though.Here we are deleting last 3 lines from a file.

#!/bin/bash
#Assign the number of lines to be deleted to variable "a"
a=3
i=1
while [ $i -le $a ]
do
sed -i '$d' file
i=$(($i + 1))
done
Member
Posted in Uncategorized
Views 6225 Comments 2 dinakumar12 is offline

  



All times are GMT -5. The time now is 07:07 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration