Here it is searching for key record type C and then making a key DOC used to write in different file. And other records in same file.
But my problem here is as grep is searching for DOC as same sequence in file it is not able to find the DOC key we made for the record type C and this record is not getting written in the output file.
How can i make this grep to search both type of keys?
Thanks!
---------- Post updated at 04:56 PM ---------- Previous update was at 03:06 PM ----------
I have tried grep but i am not able to implement it.
I have an idea
i think in loop
I can put another grep which will search for the records matching the key
and append to file.
But my problem is i am not able to do multiple search in grep
Example input file
Its an fixed width file
1 12367 A 1100
2 12367 B 2200
3 12367 C 3300
C 123 D 4467
1 12467 A 1100
2 12467 B 2200
3 12467 C 3300
C 124 D 4467
So here for C record we are picking first 3 and adding the "67" value to make 5 digit key.
To generate the output files as
Filename : DOCKET_12367
1 12367 A 1100
2 12367 B 2200
3 12367 C 3300
C 123 D 4467
Filename : DOCKET_12467
1 12467 A 1100
2 12467 B 2200
3 12467 C 3300
C 124 D 4467
---------- Post updated at 05:20 PM ---------- Previous update was at 05:16 PM ----------
This are smale files and not the actual file which i am using for my code as i have pasted my code in 1st post
you can try using flags. see below this might be helpful to you.
var=1
for DOC in `InputFileName | awk '{ if ( substr($0, 392, 1)=="C") { $0 = (substr($0, 28, 15) "" substr($0, 386, 3)) } else { ($0 = substr($0, 28, 18))}; print }' | sort | uniq`
do
if [[ ##check if var is odd ]]
then
grep ${DOC} InputFileName > DOCKET_${DOC}.txt
else
UR_CODE for Second key
fi
var++
done
I i tried your script.
But i am getting only one output row as output and that is also the last row of the file.
And also in send awk i am not able to understand where we are doing the column comparison for it.
To genrate different doc
---------- Post updated at 06:36 PM ---------- Previous update was at 06:29 PM ----------
Hi My level is two small to
understand this so difficult code.
But thanks for you efforts.
I tried executing it But it is generating 3 different files for 3 input record.
And contain one record per file
---------- Post updated at 06:42 PM ---------- Previous update was at 06:36 PM ----------
And my problem is not generating the DOC key value my code is running fine for it.
My problem is to search the same DOC key value splitting it and match with different columns for record type C.
And if it matches to be written in the same DOC key file i am writing for.
$ head kam_*.txt
==> kam_12367.txt <==
1 12367 A 1100
2 12367 B 2200
3 12367 C 3300
C 123 D 4467
==> kam_12467.txt <==
1 12467 A 1100
2 12467 B 2200
3 12467 C 3300
C 124 D 4467
$
syntax error The source line is 6.
The error context is
print $0 > >>> $WOR/WORK_${ <<<
awk: The statement cannot be correctly parsed.
The source line is 6.
awk: Quitting
The source line is 6.