- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- display range of 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
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-21-2003 11:50 AM
тАО10-21-2003 11:50 AM
awk 'NR==$n, NR==$m {print $0}' file.out
to print the lines of file.out whose numbers are stored in the variables m & n.
Can anyone please help me in this. Is there any other ways to display a range of lines from a file. The line numbers should be obtianed from the variables that holds them.
Thanks,
Andy
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 11:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 11:56 AM
тАО10-21-2003 11:56 AM
Re: display range of lines from a file
if ( NR >= start && NR <= end ) print $0;
}' file.out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 11:58 AM
тАО10-21-2003 11:58 AM
Re: display range of lines from a file
NR > '$n' {exit;}
NR >='$m' {print $0;}' file.out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 12:04 PM
тАО10-21-2003 12:04 PM
Re: display range of lines from a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 12:07 PM
тАО10-21-2003 12:07 PM
Re: display range of lines from a file
there is a few different ways to do it
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 12:14 PM
тАО10-21-2003 12:14 PM
Re: display range of lines from a file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 01:10 PM
тАО10-21-2003 01:10 PM
Re: display range of lines from a file
http://66.34.90.71/ITRCForumsEtiquette/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 06:31 PM
тАО10-21-2003 06:31 PM
Re: display range of lines from a file
head -$m file.out | tail -`expr $m - $n`
The problem with your line is that the shell will not replace $n and $m, because it is enclosed in single quotes, which is needed because of the $0 you use for the print. But you since you want to print the entire line, you can do it also using double qoutes.
Another thing is the way you try to do the range. Do you know beforehand which is the bigger one? If not, a better awk version would be:
awk "BEGIN { if ($n > $m) { start=$m;end=$n} else {start=$n;end=$m}}
NR >= start && NR <= end { print}" file.out
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2003 08:06 PM
тАО10-21-2003 08:06 PM
Re: display range of lines from a file
my guess is that you want to grep for a string in a file and have some lines before and after the string displayed. If that is the case, try the attached script, which needs three parameters: $1= the string to grep for, $2= the number of lines to print before and after the string, $3= the file.
regards,
John K.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-22-2003 07:56 PM
тАО10-22-2003 07:56 PM
Re: display range of lines from a file
`cat -n file.out | egrep "$n|$m"`