Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting last 7 lines from a file using awk or sed 1

Status
Not open for further replies.

applebala

Programmer
Mar 6, 2001
8
0
0
US
Hi Everyone

I want to delete last 7 lines from a bunch of files. Can anyone help me on this. You can suggest any unix utility which does this and how it should be done..
say awk or sed or ?.

Thanks in advance
Bala



 
Hi Bala,

This should do it for you:


#!/bin/sh

cd $1

for i in `ls -1 $1 | cat`
do
count=`cat $i | wc -l`
last=$count
last=`expr $last - 7`
nawk 'NR == 1, NR == '"$last"' {print}' $i > $i.new
done
cd


Hope this helps you!


flogrr
flogr@yahoo.com

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top