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!

Everything except last two lines of file 3

Status
Not open for further replies.

smicro

MIS
Dec 26, 2002
281
0
0
US
Is there a way to print all lines except the last two. I have the below command which prints the last two lines but I need it to print the opposite, everything except the last two lines. The number of lines will always be different but I need it to consistently not print the last two lines. Basically this is to get a listing of files to delete for a certain size and the last two created we didn't want to delete. Thanks.

ls -l | awk '{if ($5 >314572800) print $0}' |tail -2
 
Thread822-1615529 might give you some ideas to work with.

The internet - allowing those who don't know what they're talking about to have their say.
 
Or alternatively, add them to an array and then print the contents of the array except the last two items:

Code:
ls -l | awk '{ if ($5 > 314572800) a[++i]=$0 } END { for (j=1; j<i-1; j++) print a[j] }'

Annihilannic.
 
the last two [!]created[/!]
ls -l[!]t[/!] | ...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
True... I sholud have said I was assuming the files are named in such a way that the newest ones will always be listed last in ls -l.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top