- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- AWK line grab
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
тАО06-21-2013 01:54 AM
тАО06-21-2013 01:54 AM
Hello,
I'm looking for an AWK solution for the following.
Using the below input file I would like to select a date (Mon-Fri) and then:
1. Print the current line
2. Print the next week day line (i.e. Mon-Fri) however if that day is a "XXX" line it must be the next day
Thanks in advance for any solutions.
Input file
01/01/2013:Tue :
02/01/2013:Wed :
03/01/2013:Thu :XXX
04/01/2013:Fri :
05/01/2013:Sat :
06/01/2013:Sun :
07/01/2013:Mon :
08/01/2013:Tue :
09/01/2013:Wed :
10/01/2013:Thu :
11/01/2013:Fri :XXX
12/01/2013:Sat :
13/01/2013:Sun :
14/01/2013:Mon :XXX
15/01/2013:Tue :
16/01/2013:Wed :
17/01/2013:Thu :
18/01/2013:Fri :
19/01/2013:Sat :
Sample desired output for 3 sample runs
Run #1
Select=01/01/2013
01/01/2013:Tue :
02/01/2013:Wed :
Run #2
Select=04/01/2013
04/01/2013:Fri :
07/01/2013:Mon :
Run #3
select=10/01/2013
10/01/2013:Thu :
15/01/2013:Tue :
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-21-2013 05:03 PM - edited тАО06-21-2013 05:03 PM
тАО06-21-2013 05:03 PM - edited тАО06-21-2013 05:03 PM
SolutionYou've neglected to assign kudos and mark a solution to your previous awk query:
>I'm looking for an awk solution for the following.
Perhaps something like the following, where $select is your date.
awk -F: -v select=$select '
BEGIN { found_it = 0 }
# find next week day after select, skipping XXX days
found_it {
if ($2 == "Sat " || $2 == "Sun ") next
if ($3 == "XXX") next
print $0
exit
}
$1 == select {
found_it = 1
print $0
next
}' input-file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2013 05:51 AM
тАО06-22-2013 05:51 AM
Re: awk line grab
Thank you Dennis - a great reply.
I take it the 'fount_it' block is the equivalent of saying:
if(found_it==1)
... and could follow the '$1 == select' block of code?
Thanks again.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-22-2013 09:13 PM - edited тАО06-23-2013 05:36 AM
тАО06-22-2013 09:13 PM - edited тАО06-23-2013 05:36 AM
Re: awk line grab
>the found_it block is the equivalent of saying: if (found_it==1)
More accurately: found_it != 0.
>could follow the "$1 == select" block of code?
Provided you don't have duplicate dates.
Also, it would be helpful to others to mark the the solution post with the Accept as Solution button.