- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- How to get all but last 2 lines from text file ?
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
Forums
Discussions
Discussions
Discussions
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
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
02-02-2005 06:42 AM
02-02-2005 06:42 AM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2005 06:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2005 06:58 AM
02-02-2005 06:58 AM
Re: How to get all but last 2 lines from text file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2005 07:14 AM
02-02-2005 07:14 AM
Re: How to get all but last 2 lines from text file ?
(( numline = numline - 2))
counter=1
while read -r filedata
do
if [ $counter = $numline ]
then
exit 0
else
# do something with data
fi
(( counter = counter + 1)) #increment
done < filename
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2005 08:20 AM
02-02-2005 08:20 AM
Re: How to get all but last 2 lines from text file ?
awk '{count++}count
Best regards,
Oz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2005 08:35 AM
02-02-2005 08:35 AM
Re: How to get all but last 2 lines from text file ?
I've noticed in files that are unusually large, the head & tail commands kind of just poop-out on you. Meaning I've noticed that they generally can't handle more than "some number" of lines - but I forget how many -but I've run into it. On the other hand on small(ish) files I've used your approach often.
So, I'll have to go with S. Protter's suggestion...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-02-2005 05:47 PM
02-02-2005 05:47 PM
Re: How to get all but last 2 lines from text file ?
Install vim :P. It is free and it handles big files a tad better.
Regards
Gerhard
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 07:57 AM
02-03-2005 07:57 AM
Re: How to get all but last 2 lines from text file ?
cnt=$(cat infile | wc -l)
(( cnt = cnt - 2 ))
awk -v count=$cnt 'NR <= count {print $0}' infile > outfile
Marlou
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-03-2005 09:15 AM
02-03-2005 09:15 AM