Solved

to add header to CSV file

Posted on 2008-10-22
10
803 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

707 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now