- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Delete last two lines
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 01:56 AM
тАО08-26-2004 01:56 AM
Re: Delete last two lines
perl -ne 'push(@last2,$_); if (scalar @last2 > 2) { print shift @last2}'
By pushing each line onto a stack this script will not print the last 2 lines.
HTH
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 02:00 AM
тАО08-26-2004 02:00 AM
Re: Delete last two lines
Assigning points to indicate which solution you think works the best is what helps the forum help others...
-- Rod Hills
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 02:13 AM
тАО08-26-2004 02:13 AM
Re: Delete last two lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 02:15 AM
тАО08-26-2004 02:15 AM
Re: Delete last two lines
Here is a one-pass in awk which does no create a temp file.
It uses a 'circular buffer' of the target 'missing line' count 'L'.
This is done with an array 'line' indexed by the current record number (NR) modulus that L.
You provide a desired value for L as argument.
We start printing from the array only after L lines have come by, 'falling behind' by L lines.
Sounds tricky? Here is the 'one line' code:
awk -vL=2 '{if(NR>L){print line[(NR-L)%L];line[NR%L]=$0}}' your-file
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 06:13 PM
тАО08-26-2004 06:13 PM
Re: Delete last two lines
And you have a closing curly bracket wrong, resulting in missing the first lines...
So the right solution would be:
awk -vL=2 '{if(NR>L){print line[NR%L];}line[NR%L]=$0}' my_file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 06:18 PM
тАО08-26-2004 06:18 PM
Re: Delete last two lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 07:23 PM
тАО08-26-2004 07:23 PM
Re: Delete last two lines
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-28-2004 01:37 AM
тАО08-28-2004 01:37 AM
Re: Delete last two lines
Ayup, just a touch more general purpose. I had missed the awk part of your solution.
Elmar> but my mathematic mind says you need to remove the -L in your solution.
Ayup, a simplication I overlooked this time.
Elmar> It does nothing in the end... since (NR-L)%L equals NR%L.
Ayup, other then to make the code more clear.
Elmar> And you have a closing curly bracket wrong, resulting in missing the first lines...
Ooops! Thanks for catching that.
Groetjes,
Hein.
- « Previous
-
- 1
- 2
- Next »