LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-09-2007, 04:03 AM   #1
indyn00b
LQ Newbie
 
Registered: May 2007
Posts: 2

Rep: Reputation: 0
"catting" files in one file side by side, not among each other


Hi!

I want to write a script that takes several files and places the data in these files side by side like a table. Something like "cat *.dat >> target.dat" but side by side for every .dat. Is this somehow possible? With standard tools?

Regards,
n00b
 
Old 05-09-2007, 04:21 AM   #2
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 37
Code:
paste *.dat>target.dat
 
Old 05-09-2007, 07:35 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by radoulov
Code:
paste *.dat>target.dat
I think OP actually wants the data interleaved---ie each entry in a file is listed next to the correspnding entry in another file.

I would say set up a loop which reads one line from each file and puts the data into an array--which then can be written out to a new file.

PSEUDO-CODE:
Code:
N = 1   (line counter)
array (X,Y)
start loop
  read file1, line N into array (1,N)
  read file2, line N into array (2,N)
  etc.
  increment N
end loop
write array > newfilename
 
Old 05-09-2007, 07:43 AM   #4
radoulov
Member
 
Registered: Apr 2007
Location: Milano, Italia/Варна, България
Distribution: Ubuntu, Open SUSE
Posts: 212

Rep: Reputation: 37
Quote:
Originally Posted by pixellany
I think OP actually wants the data interleaved---ie each entry in a file is listed next to the correspnding entry in another file.
[...]
Which is what the paste command/utility does:

Code:
$ cat file1
1 a
2 a
$ cat file2
1 b
2 b
$ paste file1 file2
1 a     1 b
2 a     2 b

Last edited by radoulov; 05-09-2007 at 07:56 AM.
 
Old 05-09-2007, 09:54 PM   #5
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Quote:
Originally Posted by radoulov
Which is what the paste command/utility does:
That's not totally obvious from the man page, but I certainly don't doubt what you are saying.

It seems obvious that past expects data in a certain format....
 
Old 05-10-2007, 01:05 AM   #6
indyn00b
LQ Newbie
 
Registered: May 2007
Posts: 2

Original Poster
Rep: Reputation: 0
Hi!
"paste" did exactly what I wanted, many thanks!

-n00b
 
  


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
LXer: Top Linux photo managers side-by-side LXer Syndicated Linux News 0 12-14-2006 06:33 PM
"Back" and "Forward" side-buttons of my mouse Unforgiven79 Linux - Hardware 1 10-31-2006 12:10 AM
latex, floating tables side by side? hedpe Programming 3 10-29-2006 10:39 AM
Is screen what im looking for for side by side shells? dr_zayus69 Linux - Software 9 05-01-2006 02:53 AM
"Get the facts", from the other side... Mega Man X General 9 05-27-2005 10:49 AM

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

All times are GMT -5. The time now is 05:14 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