- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: display a specific line 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
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
11-02-2000 07:14 PM
11-02-2000 07:14 PM
I need to read a specific line from an input file. Is there any unix command syntax like,
unixcmd 4 file_name
where 4 is the line number to be read.
Thank you.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2000 07:24 PM
11-02-2000 07:24 PM
Re: display a specific line from a file
sed -n 4p file_name
but if you have any other suggestion, please let me know too. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2000 09:51 PM
11-02-2000 09:51 PM
Re: display a specific line from a file
One of the other way to do the same is:
# awk -v line=5 'NR == line { print $0 }' /etc/passwd
You can replace 5 with any shell variable if you need to. Here I have taken the file /etc/passwd.
Enjoy !
......Madhu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-02-2000 11:19 PM
11-02-2000 11:19 PM
Re: display a specific line from a file
cat file | awk '{ if (NR==5) {print $0}}'
regards,
federico
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2000 03:06 AM
11-03-2000 03:06 AM
Re: display a specific line from a file
But if you have to select a known line by number sed is the fastest.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-03-2000 03:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2000 07:40 PM
11-16-2000 07:40 PM
Re: display a specific line from a file
head -X
where X is the line number to be displayed.
Of course though, sed is the way to go.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-16-2000 09:28 PM
11-16-2000 09:28 PM
Re: display a specific line from a file
There are many ways to achieve what you want, including a for or while loop, but 'sed' is definitely the way to go.
sed -n ${LINENUM}p < filename
even allows you to have your line number in a variable
sed -n ${FIRST},${LAST}p < filename
will print lines from FIRST to LAST
There should be a space after the '-n' and no space before 'p'
Dan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2006 06:05 AM
03-30-2006 06:05 AM
Re: display a specific line from a file
ex junk.txt << EOF
5p
EOF
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2006 06:29 AM
03-30-2006 06:29 AM
Re: display a specific line from a file
awk 'NR==4 {print $0}' test
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-30-2006 06:33 AM
03-30-2006 06:33 AM
Re: display a specific line from a file
showline.sh:
awk -v LINE=$1 'NR==LINE {print $0}' $2
Usage:
showline.sh