I have data file with null record separator and end of line as field separator. See below.
Date
pattern2
pattern3
pattern1
Date
pattern1
pattern2
pattern8
Date
pattern5
pattern6
pattern2
Date
pattern1
pattern2
I am only interested in field with pattern1. The problem is field number for pattern1 changes and in some records pattern1 doesn't exist.
I want to convert above data file so that only date and pattern1 is printed and if pattern1 is not found then date and 0 is printed. Desired output format is shown below.
Date,pattern1 (If pattern1 exists)
Date,0 (If pattern1 field doesn't exist)
Can someone throw some ideas on how to search and print only that field which matches pattern?
Date
pattern2
pattern3
pattern1
Date
pattern1
pattern2
pattern8
Date
pattern5
pattern6
pattern2
Date
pattern1
pattern2
I am only interested in field with pattern1. The problem is field number for pattern1 changes and in some records pattern1 doesn't exist.
I want to convert above data file so that only date and pattern1 is printed and if pattern1 is not found then date and 0 is printed. Desired output format is shown below.
Date,pattern1 (If pattern1 exists)
Date,0 (If pattern1 field doesn't exist)
Can someone throw some ideas on how to search and print only that field which matches pattern?