Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

to add header to CSV file

Posted on 2008-10-22
10
Medium Priority
?
817 Views
Last Modified: 2013-12-27
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..
0
Comment
Question by:conversekid
  • 6
  • 4
10 Comments
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 22775546
(head -1 file1.csv ; cat file2.csv) > tmp.csv
mv tmp.csv file2.csv
0
 

Author Comment

by:conversekid
ID: 22775907
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
 

Author Comment

by:conversekid
ID: 22775925
One more thing after inserting ..Can we rename all the files with timestamp_filename...
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Accepted Solution

by:
Brian Utterback earned 2000 total points
ID: 22776173
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
 

Author Comment

by:conversekid
ID: 22777960
Great.Thanks for your help!!!!
0
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 22778104
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
 

Author Comment

by:conversekid
ID: 22778183
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
 

Author Comment

by:conversekid
ID: 22794434
Blu,

I have one more request.
http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Q_23843666.html 
...Pls check if possible
0
 
LVL 22

Expert Comment

by:Brian Utterback
ID: 22795655
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
 

Author Comment

by:conversekid
ID: 22803535
Hi Blu,

I am sorry. Please check now. Thanks...
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
I promised to write further about my project, and here I am.  First, I needed to setup the Primary Server.  You can read how in this article: Setup FreeBSD Server with full HDD encryption (http://www.experts-exchange.com/OS/Unix/BSD/FreeBSD/A_3660-S…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

783 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question