Solved

to add header to CSV file

Posted on 2008-10-22
10
809 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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:
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Shell script to extract rar files in severa directories 7 115
spectrum scale snapshot  resotre/mount 1 58
Using an inventory file in a script 7 43
sqlldr issue 1 35
When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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.:

752 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