- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: awk and string variable...
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-19-2004 02:42 AM
тАО10-19-2004 02:42 AM
awk and string variable...
Program Start => 10:47
name time day
John 11:09 Monday
Bill 11:11 Tuesday
Sam 11:38 Wednesday
Program End => 12:15
Program Start => 15:38
name time day
John 15:55 Monday
Bill 16:10 Tuesday
Sam 18:21 Wednesday
Program End => 18:44
How do I print just the first block???
awk '/Program Start => 10:47/,/Program End => 12:15/ {print $0}
Putting it in quotes doesn't work... neither does using a variable or maybe I am just assigning it wrong???
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 02:47 AM
тАО10-19-2004 02:47 AM
Re: awk and string variable...
awk '/Program Start => 10:47/,/Program End => 12:15/ {print $0}' thefile
Also if you just want to display the block you can ommit {print $0} altogether, as awk will just display the matching line(s).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 02:48 AM
тАО10-19-2004 02:48 AM
Re: awk and string variable...
I put your sample text into a file named testawk.txt and I got this to work:
>awk '/Program Start => 10:47/,/Program End => 12:15/ {print $0}' testawk.txt
Program Start => 10:47
name time day
John 11:09 Monday
Bill 11:11 Tuesday
Sam 11:38 Wednesday
Program End => 12:15
JP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 02:53 AM
тАО10-19-2004 02:53 AM
Re: awk and string variable...
awk 'found != 1 && /Program Start/,/Program End/{print ; found=1}' filename
This way the time stamp wouldn't matter, and it would always display just the first block.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 02:54 AM
тАО10-19-2004 02:54 AM
Re: awk and string variable...
start_time="Program Start => 10:47"
end_time="Program End => 12:15"
awk -v start=$start_time end=$end_time '/start/,/end/ {print $0}'
????
- Tags:
- variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 02:59 AM
тАО10-19-2004 02:59 AM
Re: awk and string variable...
end="Program Start => 12:15"
awk "/$start/,/$end/" filename
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 03:40 AM
тАО10-19-2004 03:40 AM
Re: awk and string variable...
how about printing out the lines where the first header is the same for every block but the last line is different:
Program Start
name time day
John 11:09 Monday
Bill 11:11 Tuesday
Sam 11:38 Wednesday
Program End => 12:15
Program Start
name time day
John 15:55 Monday
Bill 16:10 Tuesday
Sam 18:21 Wednesday
Program End => 18:44
The awk prints both blocks...
How do I print just the first one if the header is the same??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 03:43 AM
тАО10-19-2004 03:43 AM
Re: awk and string variable...
1> awk '/Program Start => 10:47/,/Program End => 12:15/ {print $0}'
2>
start_time="Program Start => 10:47"
end_time="Program End => 12:15"
awk -v start="$start_time" -v end="$end_time" '{ if ($0==start) while ( $0!=stop ) { getline;if ($0!=stop ) print $0 }}' testfile
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-19-2004 05:52 PM
тАО10-19-2004 05:52 PM
Re: awk and string variable...
Example:
# cat testfile
Program Start
name time day
John 11:09 Monday
Bill 11:11 Tuesday
Sam 11:38 Wednesday
Program End => 12:15
Program Start
name time day
John 15:55 Monday
Bill 16:10 Tuesday
Sam 18:21 Wednesday
Program End => 12:15
# awk '/Program Start/,/Program End => 12:15/ { if ($0=="Program Start") i++; if (i==1) print $0 }' testfile
Program Start
name time day
John 11:09 Monday
Bill 11:11 Tuesday
Sam 11:38 Wednesday
Program End => 12:15
If you want to change block number then chnage on,
if (i==
HTH.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО10-21-2004 05:33 AM
тАО10-21-2004 05:33 AM