LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-16-2008, 03:41 AM   #1
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Rep: Reputation: 15
Combine output of multiple files in one CSV file


Hi,

I have 3 files below

$cat test1
a
b
c

$cat test2
i
j
k

$cat test3
x
y
z

I want to combine all these files into one csv file.

My final file should look like this:

$cat final
a,i,x
b,j,y
c,k,z

please help.
 
Old 07-16-2008, 03:51 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Code:
paste -d, test1 test2 test3
See man paste for future reference.
 
1 members found this post helpful.
Old 07-17-2008, 01:44 AM   #3
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Original Poster
Rep: Reputation: 15
Thanks colucix
I had never heard of paste command in unix. This really helpful command. I was thinking of writing a code to accomplish this. But this command really eased all my presssure.

However I am facing some problem with this command as well.

I ave following two files

$cat account_name
quantsre
fnguide
paclife

$cat success_internal
Internal: 14/07/2008 21:10:58 (10.56.208.18)
Internal: 09/06/2008 13:18:48 (10.2.104.147)
Internal: 07/07/2008 11:52:04 (10.2.200.89)


when i use paste command as specified by you i dont get expected result though

$paste -d, account_name success_internal
,Internal: 14/07/2008 21:10:58 (10.56.208.18)
,Internal: 09/06/2008 13:18:48 (10.2.104.147)
,Internal: 07/07/2008 11:52:04 (10.2.200.89)


whereas expected result was

quantsre,Internal: 14/07/2008 21:10:58 (10.56.208.18)
fnguide,Internal: 09/06/2008 13:18:48 (10.2.104.147)
paclife,Internal: 07/07/2008 11:52:04 (10.2.200.89)

I am using Solaris 5.8, bash shell. I will try it on linux box in some time.

-Ravi
 
Old 07-17-2008, 02:51 AM   #4
say_hi_ravi
Member
 
Registered: Jan 2008
Posts: 75

Original Poster
Rep: Reputation: 15
Hi,

I could find out the problem why it was happening.

I had transferred files (account_name and success_internal) from windows machine to solaris. So there was a carriage return character (^M ) at the end of each line. When i used to open it in vi editor it looks like something like this

$vi account_name
quantsre^M
fnguide^M
paclife^M


I deleted these characters with the help of dos2unix command

$dos2unix account_name account_name

And this solved my problem

Thanks,
Ravi
 
Old 07-17-2008, 03:04 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Very good. Indeed, I tested the paste command on Solaris 5.8 and it works as well.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
combine multiple files into one file? baddah Linux - Newbie 10 09-06-2011 11:22 AM
send output of namp scan to CSV file rsmccain Linux - Networking 11 04-18-2009 08:31 PM
Comparing two csv files and write different record in third CSV file irfanb146 Linux - Newbie 3 06-30-2008 09:15 PM
Culling Data from a CSV file to output in excel jterr02 Programming 2 05-19-2006 04:58 AM
Combine multiple wmv files to one large file drkstr Linux - Software 4 04-26-2006 11:50 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:29 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration