Best way to pull out specifc lines from text file? JREPL?
Posted: 23 Sep 2021 03:47
HI Folks -
I have the following text file that is an output from a data load process I run. I need to scan the file and if an instance of "| Error: " is found, I need to create another file with a header and applicable rows.
Here is my file which I have pulled out at the etra garbage to keep it short:
As stated if "| Error: " is found (and I need to search that exact string as there are other instances with "Error:" that I don't want to include) I then need to find the line that contains SELECT '"'||ACCOUNT||'"' and then parse that line as my header and then parse the contents of the "| Error: " lines accordingly after the 3rd instance of PIPE:
I need my results as follows:
Is that possible? I have this code to grab the applicable lines but I'm not sure if I should be parsing each piece separately or if I can spool to a temp file and parse all at the same time?
I have the following text file that is an output from a data load process I run. I need to scan the file and if an instance of "| Error: " is found, I need to create another file with a header and applicable rows.
Here is my file which I have pulled out at the etra garbage to keep it short:
Code: Select all
2021-09-15 10:07:01,454 DEBUG [AIF]: Obtained connection to essbase cube: FinPlan
2021-09-15 10:07:01,496 DEBUG [AIF]: enableZeroLoad:
2021-09-15 10:07:01,496 DEBUG [AIF]: SELECT '"'||ACCOUNT||'"','"'||ENTITY||'"','"'||UD1||'"','"'||UD2||'"','"'||UD3||'"','"'||UD4||'"','"'||UD5||'"','"'||SCENARIO||'"','"'||YEAR||'"','"'||PERIOD||'"',AMOUNT
2021-09-15 10:07:02,068 DEBUG [AIF]: Locked rule file: AIF0002
2021-09-15 10:07:02,078 INFO [AIF]: Loading data into cube using data file...
2021-09-15 10:07:02,182 INFO [AIF]: purge data file: /u03/inbox/outbox/FinINTEL_2185.dat
2021-09-15 10:07:02,191 INFO [AIF]: Load data encountered the following errors:
| Error: 3303 | DP_0A10 | "AC_505110","DP_0A10","Final","BL_ALDPT","No Market","Load","PD_000000000","Actual","FY21","Aug",241.7 |
| Error: 3303 | DP_0A10 | "AC_505120","DP_0A10","Final","BL_ALDPT","No Market","Load","PD_000000000","Actual","FY21","Aug",5254.76 |
| Error: 3303 | DP_0A10 | "AC_505130","DP_0A10","Final","BL_ALDPT","No Market","Load","PD_000000000","Actual","FY21","Aug",130.19 |
| Error: 3303 | DP_0A10 | "AC_505140","DP_0A10","Final","BL_ALDPT","No Market","Load","PD_000000000","Actual","FY21","Aug",819.02 |
| Error: 3303 | DP_0A10 | "AC_505200","DP_0A10","Final","BL_ALDPT","No Market","Load","PD_000000000","Actual","FY21","Aug",270.09 |
| Error: 3303 | DP_0A10 | "AC_505300","DP_0A10","Final","BL_ALDPT","No Market","Load","PD_000000000","Actual","FY21","Aug",-6.37 |
| Error: 3303 | DP_0A10 | "AC_505400","DP_0A10","Final","BL_ALDPT","No Market","Load","PD_000000000","Actual","FY21","Aug",4.35 |
I need my results as follows:
Code: Select all
ACCOUNT,ENTITY,UD1,UD2,UD3,UD4,UD5,SCENARIO,YEAR,PERIOD,AMOUNT
AC_505110,DP_0A10,Final,BL_ALDPT,No Market,Load,PD_000000000,Actual,FY21,Aug,241.7
AC_505120,DP_0A10,Final,BL_ALDPT,No Market,Load,PD_000000000,Actual,FY21,Aug,5254.76
AC_505130,DP_0A10,Final,BL_ALDPT,No Market,Load,PD_000000000,Actual,FY21,Aug,130.19
AC_505140,DP_0A10,Final,BL_ALDPT,No Market,Load,PD_000000000,Actual,FY21,Aug,819.02
AC_505200,DP_0A10,Final,BL_ALDPT,No Market,Load,PD_000000000,Actual,FY21,Aug,270.09
AC_505300,DP_0A10,Final,BL_ALDPT,No Market,Load,PD_000000000,Actual,FY21,Aug,-6.37
AC_505400,DP_0A10,Final,BL_ALDPT,No Market,Load,PD_000000000,Actual,FY21,Aug,4.35
Code: Select all
FINDSTR /C:"||ACCOUNT||" /C:"| Error: " "DMLog.txt" >>output.txt