0

I have 2 fixed-length flat files F1 and F2 containing data (id, A, B) and (id, C, D) respectively.

I am trying to instantiate an object Foo f = new Foo (id, A, B, C, D).

How can I achieve this feat with spring batch. I don't have access to any DB so I can't insert Foo(id, A, B) into a staging table and then update the missing values.

Thank you so much :)

4
  • 1
    Why would you want to use a database to stage it. That is a LOT of slow blocking I/O and a major failure point. Spring already does this. Just need to create a flow with multiple steps. Step 1 loads file one and populated an object. That step's output goes to step 2 which load the next file and populates the other fields and then output's to what ever you want. Commented Jun 7, 2022 at 17:19
  • Thank you for the answer @BrianC, I'm just starting with Spring batch, how can I pass the output of step 1 to step 2? Commented Jun 7, 2022 at 21:08
  • 1
    Does this answer your question? That said, do you really need Spring Batch for that? Something like unix.stackexchange.com/questions/113898/… should do the trick for you. Once that sorted, you can use a SystemCommandTasklet to merge files and then use a chunk-oriented step to process the merged file containing prepared data like you expect it. Commented Jun 8, 2022 at 8:43
  • Thank you so much @MahmoudBenHassine, I will read attentively these threads, attempt to properly implement a solution, and get back with an answer. Commented Jun 8, 2022 at 11:14

1 Answer 1

0

Thank you Mahmoud Ben Hassine, using an awk script solved my issue, here's my script

awk 'NR==FNR  
{dossier[$3] = $0;next}
 {
    printf("<client>\n");   
    printf "<rev>%s</rev>\n<pdd>%s</pdd>\n",$0,dossier[$9];
    print("</client>")
  }' pdddos.txt revass.txt > output.txt
sed -i '1s/^/<clients>\n/' output.txt
sed -i -e '$a</clients>' output.txt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.