Concatenate files into one single file

I am trying to concatenate the following individual files into one file based on the current date that is attached to the individual file names.
For eg: There could be several files. One of the file name appears like SVCTURN_ON_SO2_29JAN2014_075144.txt and another as PNDGSVCORD_SO1_29JAN2014_075153.txt and so on..
I need to find a way to concatenate these individual files that includes the current date in the name.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
Are you familiar with the cat command?
baralpAuthor Commented:
yes I am familiar with cat. I can do something like this cat *.txt >> all.txt. But I don't know how to concatenate those files that have current date attached in the file name. For eg. you can see the current date on the file SVCTURN_ON_SO2_26Feb2014_075144.txt that I need to look to concatenate.
This should do it:

for i in `ls | grep 29JAN`; do cat $i >> newfile.txt; done

It will find all the files in the current working directory that have 29JAN in them (current date) and then one by one put the contents of that file into newfile.txt.
Protecting & Securing Your Critical Data

Considering 93 percent of companies file for bankruptcy within 12 months of a disaster that blocked access to their data for 10 days or more, planning for the worst is just smart business. Learn how Acronis Backup integrates security at every stage

SeanSystem EngineerCommented:

## date format ##

## Backup path ##

for i in /etc/logs/*
cat $i >> $FILE

This should do close to what you want. May need to change the paths/names etc but just put this into a shell script and run it.
baralpAuthor Commented:
In your command for i in `ls | grep 29JAN`; do cat $i >> newfile.txt; done
Can we replace 29Jan with the current date variable since the file name changes according to the run date?
SeanSystem EngineerCommented:
now=$(date +"%m_%d_%Y")

for i in `ls | grep $now`; do cat $i >> newfile.txt; done

This will use the current date.
baralpAuthor Commented:
I think now=$(date +"%m_%d_%Y")  would be now=$(date +"%d_%m_%Y") as the file name appears like SVCTURN_ON_SO2_26Feb2014_075144.txt. Correct?
SeanSystem EngineerCommented:
Yes you can change it to match the file.

see reference for the different ways to use the date command.
Yes, but it has to be in the format that is in the filename.

Try this:

today=`date +%d%b`; for i in `ls | grep $today`; do echo $i >> newfile.txt; done

This will format the date to look like this: 26Feb

Which matches the examples you provided.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Assuming the files contain the date format


eg:  26Feb2014

then you can simply do

cat *$(date +%d%b%Y)* >concatenated_file
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.