Hi, I'm currently dev'ing using awk and I'm currently stuck.
Here's the file, with comments on "<--- ":
Record <--- First Pattern
Amount 1 <--- Amount on first transaction
TotalSales 0 <--- Total Sales Prior from previous transactions
Time 1:00:00 <--- Time
Orange
Record <--- Second Pattern, First Pattern for next Record
Amount 10 <--- Amount on next transaction
TotalSales 1 <--- Total Sales from previous transactions
Time 1:00:00
Orange
Grapes
Record <--- Second Pattern, First Pattern for next Record
Amount 100
TotalSales 11 <--- Total Sales from previous transactions
Time 1:00:00
Grapes
Record <--- Second Pattern, First Pattern for next Record
Amount 10 <--- Missing total sales, ignored set
Time 1:00:00
Grapes
Record <--- Second Pattern, First Pattern for next Record
TotalSales 111 <--- Missing amount, ignored set
Time 1:00:00
Grapes
Record <--- Second Pattern, First Pattern for next Record
Basically, I want to extract the lines in between the pattern match, then perform operation such as addition and validation for the lines between the pattern. If the line does not have Amount or TotalSales, it will ignore the pattern and move to the next occurrence.
@Jotne Yes, but only with gawk and mawk . Regular awk can only use a single character as a record separator (or two consecutive new lines if left blank)...
Yes correct. /Amount/ && /TotalSales/
Means line that have both Amount and TotalSales in it.
Logical and . Look at output of data in my post #6
Logical or can be used this way /Amount/ || /TotalSales/ or /Amount|TotalSales/
@Scrutinizer
Here we could have set RS=R , since capital R is only used in the Record
@Jotne, yes we could. Usually that would be too thin a solution, but in this case I guess it could sort of work... If they decided to sell Raspberries that would be regarded as a new record, but since it would not get printed the output would still be OK with this specific input...