- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: 10th line in a 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
06-15-2010 01:59 PM
06-15-2010 01:59 PM
10th line in a text file?
- Tags:
- sed
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 02:24 PM
06-15-2010 02:24 PM
Re: 10th line in a text file?
10?
$ sed -n -e '5p' < lines.txt
5
$ sed -n -e '1,4p' -e '6,$p' < lines.txt
1
2
3
4
6
7
8
9
$ cat lines.txt
1
2
3
4
5
6
7
8
9
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 02:25 PM
06-15-2010 02:25 PM
Re: 10th line in a text file?
Perhaps the easiest way is:
# sed -ne '10p' file
...which says (p)rint the 10th (one-relative) line in the file while suppressing ('-n') the printing of all other lines.
If on the other hand you want to delete the 10th line, leaving the rest:
# sed -e '10d' file > file.new
...or delete a range of lines"
# sed -e '10,20d' file > file.new
...or delete from line-10 until the end of the file:
# sed -e '10,$d' file > file.new
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 10:02 PM
06-15-2010 10:02 PM
Re: 10th line in a text file?
What about:
cat
Paul.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-15-2010 10:49 PM
06-15-2010 10:49 PM
Re: 10th line in a text file?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2010 12:52 AM
06-16-2010 12:52 AM
Re: 10th line in a text file?
First 10 lines:
$ head -10 file
Last 10 lines:
$ tail -10 file
rgs,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2010 12:54 AM
06-16-2010 12:54 AM
Re: 10th line in a text file?
use just the negation of Raj's one liner:
awk 'NR != 10' filename
mfG Peter