Merging two year files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merging two year files
# 1  
Old 08-01-2014
Merging two year files

Hi All,

I need to merge few files as below
Code:
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
Code:
ABC_TYFWFX.txt
ABC_TYFQTFX.txt
ABC_TYFMAFX.txt
ABC_TYFAVFX.txt
ABC_TYBWFX.txt


Moderator's Comments:
Mod Comment Please use CODE tags

Last edited by rbatte1; 08-01-2014 at 08:50 AM.. Reason: Added CODE tags
# 2  
Old 08-01-2014
It's a bit unclear what you want. Do you have a fixed list of input files? you could try:-
Code:
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
This User Gave Thanks to rbatte1 For This Post:
# 3  
Old 08-01-2014
Do you want the files to be merged (based on what criteria?) or just concatenated? For the latter, try
Code:
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.
This User Gave Thanks to RudiC For This Post:
# 4  
Old 08-02-2014
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

Last edited by Hypesslearner; 08-02-2014 at 03:58 AM.. Reason: Name change
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete files using year

Hi All, how can i delete files from my Unix directory on the basis of year, i have files from 2001 to till 2014, but from their, i have to delete only 2013 file.Below is my file name rwxrwxrwx 1 guopt users 5169 Jul 12 00:30 grt592_20130712003000.SAP Thanks Kki (2 Replies)
Discussion started by: kki
2 Replies

2. Shell Programming and Scripting

How to find all files for same month and year?

Hi All, I find all files for same month and year lets say there are following files in directory -rwxr-xr-x 1 user userg 1596 Mar 19 2012 c.txt -rwxr-xr-x 1 user userg 1596 Mar 21 2012 d.txt -rwxr-xr-x 1 user userg 1596 Mar 22 2012 f.txt -rwxr-xr-x 1... (8 Replies)
Discussion started by: Makarand Dodmis
8 Replies

3. Shell Programming and Scripting

Delete files older than 1 year through FTP

Hi All, I want to login to a remote server using FTP command and then check for files older than 1 year and delete those files. Please let me know how can i achieve this using Unix Commands. Thanks in Advance, (10 Replies)
Discussion started by: HemaV
10 Replies

4. UNIX for Dummies Questions & Answers

Delete files by year

can someone provide a command to delete files by year? I have several files created last year 2009. Im trying to list first ls -lrt | grep '/2009/ {print $10}' by it returns no result. Pls advise (2 Replies)
Discussion started by: lhareigh890
2 Replies

5. Red Hat

Move files of a certain year to other directory

Hi all, I have a massive amount of recording files in .WAV format stored in a directory, files dating back to 2006. It is a huge amount of files as Linux cannot even do a listing of it all, it states: "argument list too long" What I would like to do is the following: Find all the files of... (6 Replies)
Discussion started by: codenjanod
6 Replies

6. Solaris

Number of files - in start of year

Is there any way to find "Number of files" that exists on my solaris parition in the starting of 2009 year ? I know ctime or mtime will not help and unix wouldnt store creation time. Only hope i can see ( and i am not sure if that will help ) is that my system is up from last 2 years without... (5 Replies)
Discussion started by: rajwinder
5 Replies

7. UNIX for Dummies Questions & Answers

Move files based on year

Hi All, I have a directory which has crores of files since from 2003. I want to move ony the 2003 files to another directory. Please help (9 Replies)
Discussion started by: IHK
9 Replies

8. UNIX for Dummies Questions & Answers

Move files based on year

I have a directory which has crores of files since from 2003. I want to move only the 2003 files to another directory. Please help in doing this. Thanks (1 Reply)
Discussion started by: IHK
1 Replies

9. UNIX for Dummies Questions & Answers

delete compressed files from year 2005

I'm trying to delete files that were created/modified in the year 2005 that we compressed and have the .Z extension on them. I tried using the awk utility but the syntax is incorrect. I don't know how to use a wildcard to capture all the compressed files. Here's the code I used ( ls -lR |... (5 Replies)
Discussion started by: igidttam
5 Replies

10. UNIX for Dummies Questions & Answers

how to know year create/modified files?

Dear all, how to know created file time, include the year created/last modified? if using #ls -al only month date and time Thank you. (5 Replies)
Discussion started by: blesets
5 Replies
Login or Register to Ask a Question