- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- 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
Forums
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
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 12:10 AM
тАО10-01-2008 12:10 AM
I want to delete 1st 10 lines from a file.
Could you please help me to do so?
Regards
Muktha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 12:14 AM
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 12:14 AM
тАО10-01-2008 12:14 AM
Re: Delete 1st 10 lines from a file
you can use sed:
# delete the first 10 lines of a file
sed '1,10d'
check here for more handy one-liners:
http://www.student.northpark.edu/pemente/sed/sed1line.txt
regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 12:23 AM
тАО10-01-2008 12:23 AM
Re: Delete 1st 10 lines from a file
Thanks a lot..
I got the expected output.
Regards
Mukha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 03:10 AM
тАО10-01-2008 03:10 AM
Re: Delete 1st 10 lines from a file
I am facing 1 more problem , I can't give
a variable to use sed command
For example:-
sed '1,$COUNT d' File1 > File2
Its not possible.
Could please help me resolve this?
Regards
Muktha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 03:16 AM
тАО10-01-2008 03:16 AM
Re: Delete 1st 10 lines from a file
I first show the content of a test file with 20 lines.
Then the result of the tail -10 command
Cheers
../testscripts >cat 1to20.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
../testscripts >tail -10 1to20.txt
11
12
13
14
15
16
17
18
19
20
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 03:17 AM
тАО10-01-2008 03:17 AM
Re: Delete 1st 10 lines from a file
sed "1,$COUNT d" file1>file2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 03:20 AM
тАО10-01-2008 03:20 AM
Re: Delete 1st 10 lines from a file
Here it is in a script. Tweak to suit you needs.
#!/usr/bin/ksh
# set integer representing number of lines
# to remove
typeset -i i=10
tail -${i} 1to20.txt >> SOMEFILENAME.txt
exit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 03:25 AM
тАО10-01-2008 03:25 AM
Re: Delete 1st 10 lines from a file
Slow day :)
This deletes the lines from the file. And backs it up to foo.txt.old first.
If you remove the -i option then it just deletes the lines...in the ORIGINAL file. So you're working with just ONE file and not 2 as in our previous posts. (BUT I suggest to use the -i option to back it up.)
# delete first 10 lines
perl -i.old -ne 'print unless 1 .. 10' foo.txt
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-01-2008 04:40 AM
тАО10-01-2008 04:40 AM
Re: Delete 1st 10 lines from a file
Thanks a lot Sandeep .
Regards
Muktha
- 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