We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Merging file by monthdate

sam2929
sam2929 asked
on
Medium Priority
379 Views
Last Modified: 2013-11-17
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


AAK_201104191802340972_dumb.csv
AAK_201104191802355572_dumb.csv
LLK_201104191702354722_dumb.csv

KKR_201104191802340972_test.csv
BBB_201104191802355572_test.csv
LLK_201104191802354722_test.csv
Comment
Watch Question

Try:
cat *_dumb.csv >today_file_dumb.csv 
cat *_test.csv >today_file_test.csv

Open in new window

Author

Commented:
i guess i need to be bit clear i need to dump all latest file when i say latest i mean  0419 and if it don't find 0419 then find all 0418 file and append them

Author

Commented:
i guess i need to be bit clear i need to dump all latest file when i say latest i mean  all
0419( irespect of the timestamp 0419566666 or 04197777 )and if it don't find 0419 then find all 0418 file and append them)



Today=`date +%Y%m%d`
cat *_${Today}*_dumb.csv >today_file_dumb.csv 
cat *_${Today}*_test.csv >today_file_test.csv

Yesterday=`TZ=CST+24 date '+%Y%m%d'`
cat *_${Yesterday}*_dumb.csv >today_file_dumb.csv 
cat *_${Yesterday}*_test.csv >today_file_test.csv

Open in new window

Author

Commented:
Hi Mike,
This is what exactly i want and also if you can provide a ls stament which i can test before doing cat

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

Test by replacing cat with ls and comment out the redirection.

Author

Commented:
Hi Mike,
This will not work as the function is just for today and yesterday what it should do is look for latest
ddmm_reg.csv files when i say latest as they not sending files everyday so april 25 we might get april 19 3 files so we need to get latest april 19  3files.

Thanks

Author

Commented:
Hi Mike,
This script is good i need bit modification is that and that is if today is '' then we can hardcode and get
file else below,Never written script so need help
Today=`date +%Y%m%d`
cat *_${Today}*_dumb.csv >today_file_dumb.csv
cat *_${Today}*_test.csv >today_file_test.csv

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.