Merge two file based upon mmdd


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Merge two file based upon mmdd
# 1  
Old 04-24-2011
Merge two file based upon mmdd

Hi,
I want to merging all MMDD* files into one file say today_file_dumb.csv and today_file_test.csv
Files format is below.

Thanks

file looks like

AAK_201104191802340972_dumb.csv
AAK_201104191802355572_dumb.csv
LLK_201104191702354722_dumb.csv

KKR_201104191802340972_test.csv
BBB_201104191802355572_test.csv
LLK_201104191802354722_test.csv




so i want

AAK_201104191802340972_dumb.csv
AAK_201104191802355572_dumb.csv
> today_file_dumb.csv

and

KKR_201104191802340972_test.csv
BBB_201104191802355572_test.csv
LLK_201104191802354722_test.csv
>today_file_test.csv
# 2  
Old 04-24-2011
what do you really mean by MMDD* and where is this in your filename?

with the given example you can also do it like :

Code:
cat *dumb.csv >today_file_dumb.csv

and

Code:
cat *test.csv >today_file_test.csv

# 3  
Old 04-24-2011
Hi,
This will not help as i need to pick just 0419 records when i say mmdd*
i am referring to 0419 so basic idea is lets says on april 24 we get 5 files
2 files for 0419 and two files for 0418 and 1 file for 0417 we need to pick
up two files for 0419 and append them.

AAK_201104191802340972_dumb.csv
AAK_201104191802355572_dumb.csv
LLK_201104191702354722_dumb.csv
# 4  
Old 04-25-2011
so, in that case:

Code:
 
cat *0419*dumb.csv > today_file_dumb.csv

# 5  
Old 04-25-2011
We can't hard code it we need dynmaic code for it
# 6  
Old 04-25-2011
Try this ...

todays_date=`date +%m%d`


Code:
cat *$todays_date*_dumb.csv >>today_file_dumb.csv

cat *$todays_date*_test.csv >>today_file_test.csv

# 7  
Old 04-25-2011
This is perhaps overkill, but this will handle files of different dates...

In the directory with your files:
Code:
ls *csv | awk -f matcher.awk

where matcher.awk contains:

Code:
BEGIN{FS="_"}
{
    date=substr($2,5,4);
}
/dumb/ {
    system("cat " $0 " >> " date "_dumb.csv")
}
/test/ {
    system("cat " $0 " >> " date "_test.csv")
}


Last edited by kato; 04-25-2011 at 09:34 AM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

file merge based on common columns

I have two files 1.txt 34, ABC, 7, 8, 0.9 35, CDE, 6.5, -2, 0.01 2.txt 34, ABC, 9, 6, -1.9 35, CDE, 8.5, -2.3, 5.01 So in both files common columns are 1 and 2 so final o/p should look like 34, ABC, 7, 8, 0.9, 9, 6, -1.9 35, CDE, 6.5, -2, 0.01, 8.5, -2.3, 5.01 I tried using... (3 Replies)
Discussion started by: manas_ranjan
3 Replies

2. Shell Programming and Scripting

Merge file lines based off of keyword

Hello Everyone, I have two files I created in a format similar to the ones found below (character position is important): File 1: 21 Cat Y N S Y Y N N FOUR LEGS TAIL WHISKERS 30 Dog N N 1 Y Y N N FOUR LEGS TAIL 33 Fish Y N 1 Y Y N N FINS 43 CAR Y N S Y Y N N WHEELS DOORS... (7 Replies)
Discussion started by: jl487
7 Replies

3. Shell Programming and Scripting

Help with merge two file based on similar column content

Input file 1: A1BG A1BG A1BG A1CF A1CF BCAS BCAS A2LD1 A2M A2M HAT . . Input file 2: A1BG All A1CF TEMP (5 Replies)
Discussion started by: perl_beginner
5 Replies

4. Shell Programming and Scripting

Merge two files based on a 3rd key file

Hi, I want to merge the two files based on the key file's columns. The key file: DATE~DATE HOUSE~IN_HOUSE CUST~IN_CUST PRODUCT~PRODUCT ADDRESS~CUST_ADDR BASIS_POINTS~BASIS_POINTS ... The other 2 files are From_file & To_file - The From_file: DATE|date/time|29|9 ... (9 Replies)
Discussion started by: dips_ag
9 Replies

5. UNIX for Dummies Questions & Answers

Appending date value mmdd to first column in file

Hi , I have a file with a running sequence number. I need to append a date value mmdd format on to the first column. for e.g.: The file contains records as 001 abc 002 cde 003 edf 004 fgh 005 hik The output should be 1111001 abc 1111002 cde 1111003 edf 1111004 ... (1 Reply)
Discussion started by: kalyansid
1 Replies

6. Shell Programming and Scripting

Merge lines in text file based on pattern

Hello, I have searched forum trying to find a solution to my problem, but could not find anything or I did not understand the examples.... I should say, I am very inexperienced with text processing. I have a text file with approx 60k lines in it. I need to merge lines based on the number... (8 Replies)
Discussion started by: Bertik
8 Replies

7. Shell Programming and Scripting

Merge two file data together based on specific pattern match

My input: File_1: 2000_t g1110.b1 abb.1 2001_t g1111.b1 abb.2 abb.2 g1112.b1 abb.3 2002_t . . File_2: 2000_t Ali england 135 abb.1 Zoe british 150 2001_t Ali england 305 g1111.b1 Lucy russia 126 (6 Replies)
Discussion started by: patrick87
6 Replies

8. Shell Programming and Scripting

merge two two txt files into one file based on one column

Hi, I have file1.txt and file2.txt and would like to create file3.txt based on one column in UNIX Eg: file1.txt 17328756,0000786623.pdf,0000786623 20115537,0000793892.pdf,0000793892 file2.txt 12521_74_4.zip,0000786623.pdf 12521_15_5.zip,0000793892.pdf Desired Output ... (5 Replies)
Discussion started by: techmoris
5 Replies

9. Shell Programming and Scripting

Merge lines in Flat file based on first 5 characters

Hi I have the fixed width flat file having the following data 12345aaaaaaaaaabbbbbbbbbb 12365sssssssssscccccccccc 12365sssss 12367ddddddddddvvvvvvvvvv 12367 vvvvv Here the first column is length 5 second is length 10 third is length 10 if the second or third column exceeds... (3 Replies)
Discussion started by: Brado
3 Replies

10. Shell Programming and Scripting

merge based on common, awk help

All, $ cat x.txt z 11 az x 12 ax y 13 ay $ cat y.txt ay TT ax NN Output required: y 13 ay TT x 12 ax NN (3 Replies)
Discussion started by: jkl_jkl
3 Replies
Login or Register to Ask a Question