BladeSystem Forums have moved here
To make BladeSystem information easier to find, we have moved the BladeSystem forums here, to Servers and Operating Systems.
Showing results for 
Search instead for 
Do you mean 

AWK line grab

Go to Solution
Occasional Contributor

AWK line grab


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
01/01/2013:Tue :
02/01/2013:Wed :

Run #2
04/01/2013:Fri :
07/01/2013:Mon :

Run #3
10/01/2013:Thu :
15/01/2013:Tue :

Acclaimed Contributor

Re: awk line grab

[ Edited ]

You'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
$1 == select {
   found_it = 1
   print $0
}' input-file

Occasional Contributor

Re: awk line grab

Thank you Dennis - a great reply.


I take it the 'fount_it' block is the equivalent of saying:




... and could follow the '$1 == select' block of code?


Thanks again.





Acclaimed Contributor

Re: awk line grab

[ Edited ]

>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.