to add header to CSV file

Hi All,
I want to insert one line as a header to a csv file. I need to read the same from a different file. In other words I need to copy header from once .CSV file to the other..Thanks in advance..
conversekidAsked:
Who is Participating?
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.

Brian UtterbackPrinciple Software EngineerCommented:
(head -1 file1.csv ; cat file2.csv) > tmp.csv
mv tmp.csv file2.csv
0
conversekidAuthor Commented:
Great..
I have around 100 files..All of them are with .CSV extension. I have to read the file from source file and  insert this line into all the files..pls help
0
conversekidAuthor Commented:
One more thing after inserting ..Can we rename all the files with timestamp_filename...
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

Brian UtterbackPrinciple Software EngineerCommented:
head -1 file1.csv > /tmp/header
for f in *.csv
do
   fn=`date +'%y%m%d%H%M%S'`_$f
   cp /tmp/header $fn
   cat $f >>$fn
done

You may need to adjust a bit to get directories right. Also, the header file should not be in the same directory, otherwise
it will get the header added to it as well.
0

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
conversekidAuthor Commented:
Great.Thanks for your help!!!!
0
Brian UtterbackPrinciple Software EngineerCommented:
Did you really intend to mark your comment "Great.Thanks for your help!!!!" as the solution? Since you awarded the points to my comments, I suspect that you really just wanted to close the question and award the points. If so, please try again.
0
conversekidAuthor Commented:
Hi Blu,
I am really very satisified with the solution provided by you. Its working fine. I got absolutely no error. I appreciate your concern..Thanks much!!!
0
conversekidAuthor Commented:
Blu,

I have one more request.
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Q_23843666.html 
...Pls check if possible
0
Brian UtterbackPrinciple Software EngineerCommented:
I have already provided an answer on that thread.

You are misunderstanding my last comment. If you have the answer you wanted (which you indicate is the case), you should close the question, provide a grade and award the points. Instead you have indicated that the question be closed after a waiting period, with main points given to your comment, and assisted solution points given to my comments.

Please just close the question, awarding the answer points to comment  #22776173, and assisted solution to comment #22775546  is you want to.
0
conversekidAuthor Commented:
Hi Blu,

I am sorry. Please check now. Thanks...
0
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
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.