Hello all I have a slew of files I search through with 'find' recursively then once all those file types are found I want to remove all records not matching this string on each line, in this order:
INPUT||||SELECT 'BLABLA' as SOR'
- Where INPUT||||SELECT (Case insensensitive) starts a line
- Where the contents between the single quotes (BLABLA) are random so I need a wildcard here
- Where 'as SOR' is case insensitive
EXAMPLE FROM ONE OF THE DATA FILE SEARCHED:
1) INPUT||||select 'LLC'
2) INPUT||||select 'LLC' as SOR, b.cust_id_num, b.cust_federal_id_num, ...
3) INPUT||||select distinct 'LLC' as SOR, b.cust_id_num, b.cust_federal_id_num, ...
4) INPUT||||select 'BBD' as sor, b.cust_id_num, b.cust_federal_id_num, ...
5) INPUT||||SELECT 'GOD' $VAL, b.cust_ID_num, a, cust live num...
6-+++)...
Successful search should result in the following:
-1st line would be ignored, no iteration of 'as sor'
-2nd line would be captured because it meets all criteria
-3rd line would be ignored because 'distinct' appears between 'select' and 'sor'
-4th line would be captured because it meets all criteria
-5th line would be ignored, no iteration of 'as sor'
I have tried many things with no luck:
find . -type f -iname "*.dat" -exec sh -c awk '/INPUT||||select/ && /'as SOR'/' "{}" \; > FILE.log
find . -type f -iname "*.dat" -exec grep 'INPUT_SELECT\|as sor' {} \; > FILE .log
I really thought something like this was going to work in my script but no such luck!
grep -i "INPUT\||||select \<'...'\> as sor" ...
I have tried all kinds of escapes and quoting to get things right but I am still returning records that do not meet the criteria in the order mentioend. Thanks in advance!