- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- 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-25-2004 11:10 PM
тАО08-25-2004 11:10 PM
I have a file in which I don't need the last two lines. How can run a command to achieve this?
I have a work around for my collegue but he is not happy with it.
sed '$d' my_file | sed '$d'
I am expecting some thing like
sed -e '$d' -e '$d' my_file.
Please help us.
Parmy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 11:21 PM
тАО08-25-2004 11:21 PM
Re: Delete last two lines
Use "sed -e '$d' my_file |sed -e '$d'"
that should do it.
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 11:23 PM
тАО08-25-2004 11:23 PM
Re: Delete last two lines
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 11:32 PM
тАО08-25-2004 11:32 PM
Re: Delete last two lines
vi +$ my_file<
Regards
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-25-2004 11:57 PM
тАО08-25-2004 11:57 PM
Re: Delete last two lines
expr `wc -l my_file | cut -d" " -f1` - 2 | xargs echo | sed -e "s/^/head -/" -e "s/$/ my_file/" | sh > new_my_file
live free or die
harry
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 12:00 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 12:21 AM
тАО08-26-2004 12:21 AM
Re: Delete last two lines
awk -v nb=$(wc -l my_file | cut -f1 -d" ") '{if(NR>(nb - 2)) exit; print}' my_file
Regards,
Jean-Luc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 12:27 AM
тАО08-26-2004 12:27 AM
Re: Delete last two lines
head $(wc -l my_file | awk '{print "-" $1 - 2}') my_file
In vi you can use the command:
$-1,$d
to delete the last two lines. Should work in ed too.
Or a complete awk solution:
awk '{ if (NR > 2) { print prev2 } prev2=prev1;prev1=$0}' < my_file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 12:42 AM
тАО08-26-2004 12:42 AM
Re: Delete last two lines
This works ..but don't know you like it or not.
# let A=`cat file1 | wc -l`-2
# head -$A file1 >file2
That works.
Regards,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-26-2004 01:03 AM
тАО08-26-2004 01:03 AM
Re: Delete last two lines
I have no HP-UX where to try it but on Linux
exists the tac command (opposit to cat)
so maybe the following row will help you
tac file | sed '1,2d' | tac | tee file1
br Jan