- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Delete 1st 10 lines from a 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
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
тАО10-01-2008 04:41 AM
тАО10-01-2008 04:41 AM
Re: Delete 1st 10 lines from a file
Thanks to all....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 10:40 PM
тАО10-01-2008 10:40 PM
Re: Delete 1st 10 lines from a file
just a usefull tip.
You were nearly there with your sed
command, this won't work
sed '1,$COUNT d' File1 > File2
but if you use double quotes
sed "1,$COUNT d" File1 > File2
Sed is wonderfull;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 11:55 PM
тАО10-01-2008 11:55 PM
Re: Delete 1st 10 lines from a file
Didn't Sandeep already mention the quoting issue? :-)
>Kevin: tail -10 will work as shown below.
>set integer representing number of lines to remove
This is the wrong option to skip 10 lines and only works for your magic number, 20 lines. This requires you to do complex arithmetic operations in your head and know the number of lines in the file. Instead you should use this tail "+" option:
tail +$(( 10 + 1 )) 1to20.txt
- Tags:
- tail
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2008 05:20 AM
тАО10-02-2008 05:20 AM
Re: Delete 1st 10 lines from a file
>tail +$(( 10 + 1 )) 1to20.txt
You could do something like this instead of doing math ;) (in script format)
#!/bin/bash
file=1to200.txt # could use $1
offset=10 # could use $2
tail -n$((`wc -l $file` - $offset)) $file > output.file
It's untested since I don't have any machine to test it.
Best regards
Fredrik Eriksson
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-02-2008 03:24 PM
тАО10-02-2008 03:24 PM
Re: Delete 1st 10 lines from a file
I don't know why you would want to do this?
It reads the file twice and doesn't work for large files due to a limitation for HP's tail -N.
>It's untested
Here is a version that corrects it:
tail -n$(($(wc -l < $file) - $offset)) $file > output.file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2008 12:23 AM
тАО10-03-2008 12:23 AM
Re: Delete 1st 10 lines from a file
But you're right, tail does have a limit. I just haven't reached it yet :P
And in my first thought I did use $(wc -l) but thought that maybe (of some odd reason) $(()) didn't like me using that ;P
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-03-2008 12:54 AM
тАО10-03-2008 12:54 AM
Re: Delete 1st 10 lines from a file
You do NOT need to know the line count to remove the top 10 lines. You use:
tail +11 file
Similar to sed's:
sed -n '11,$p' file
- « Previous
-
- 1
- 2
- Next »