Solved

to add header to CSV file

Posted on 2008-10-22
10
806 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:blu
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
Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 
LVL 22

Accepted Solution

by:
blu earned 500 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:blu
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:blu
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
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.:

821 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