Merging two year files

Hi All,

I need to merge few files as below

ABC_NYFWFX.txt
ABC_NYFQTFX.txt
ABC_NYFMAFX.txt
ABC_NYFAVFX.txt
ABC_CYFWFX.txt
ABC_CYFQTFX.txt
ABC_CYFMAFX.txt
ABC_CYFAVFX.txt
ABC_CYBWFX.txt

ABC_NYFWFX.txt & ABC_CYFWFX.txt should be merged into a single file and name should be ABC_TYFWFX.txt

So final output should be like below

ABC_TYFWFX.txt
ABC_TYFQTFX.txt
ABC_TYFMAFX.txt
ABC_TYFAVFX.txt
ABC_TYBWFX.txt

It's a bit unclear what you want. Do you have a fixed list of input files? you could try:-

for identifier in WFX QTFX MAFX AVFX FWX
do
   cat ABC_NYF${identifier}.txt ABC_CYF${identifier}.txt  >  ABC_TYF${identifier}.txt
done

Does that do what you need? If not, can you answer these:-

  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

Regards,
Robin

1 Like

Do you want the files to be merged (based on what criteria?) or just concatenated? For the latter, try

for i in ABC_C*; do echo cat $i ${i/_C/_N} ">" ${i/_C/_T}; done
cat ABC_CYBWFX.txt ABC_NYBWFX.txt > ABC_TYBWFX.txt
cat ABC_CYFAVFX.txt ABC_NYFAVFX.txt > ABC_TYFAVFX.txt
cat ABC_CYFMAFX.txt ABC_NYFMAFX.txt > ABC_TYFMAFX.txt
cat ABC_CYFQTFX.txt ABC_NYFQTFX.txt > ABC_TYFQTFX.txt
cat ABC_CYFWFX.txt ABC_NYFWFX.txt > ABC_TYFWFX.txt

If happy, remove the echo.

1 Like

Hi Robin ,

Here is the actual requirement.. There are files generated for current year and next year in a particular folder , I need to concatenate these two files into a total year file ,

For example ABC_NYFWFX.txt and ABC_CYFWFX.txt , these two files indicate next year and current year , FWFX indicate forecast fx rates .

Yes there are fixed set of files , I am really new to unix , I have perl and shell scripting ,I just tried using cat to concatenate these , but I want to do using loop ,I hope the code given by you works ,Not tested though, Thanks Much

Regards,
DJ