LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 06-27-2012, 08:59 AM   #1
wilelucho
LQ Newbie
 
Registered: Jun 2012
Location: Brazil
Distribution: Ubuntu
Posts: 19

Rep: Reputation: Disabled
add 250 single column files to create one file


Hi every one

I have the following problem

I have 250 single column files, I would like to generate a single file with 250 columns. Each file has 18265 rows.

I tried with sed, paste, and awk. I have the impression that awk is powerful enough to do the job, however I'm learnig about it. Also paste should do the job, but it simply doesn't.

Can you help me
 
Old 06-27-2012, 09:33 AM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 640

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Hi.

Welcome to LQ!

What did you already tried? It looks like `paste' does exactly what you want:
Code:
$ cat f1
1
2
3
4
$ cat f2
a
b
c
d
e
f
$ paste f[12] f2 f1
1       a       a       1
2       b       b       2
3       c       c       3
4       d       d       4
        e       e
        f       f
What is the expected output?

Last edited by firstfire; 06-27-2012 at 09:34 AM.
 
Old 06-27-2012, 09:37 AM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,164

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Quote:
Originally Posted by wilelucho View Post
Also paste should do the job, but it simply doesn't.
paste should do the job. Why do you say it doesn't? What happens when you try?

Daniel B. Martin
 
Old 06-27-2012, 09:51 AM   #4
wilelucho
LQ Newbie
 
Registered: Jun 2012
Location: Brazil
Distribution: Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
That's right
Paste should do it

I tried

ls *.txt > lista.rtf
paste `less lista.rft` > complete_file.txt

Also I tried "manually"

paste file1.txt file2.txt file3.txt > newfile.txt
All I got is a two column file where data in files 2 and 3 are mixed up in the same column

What I would like to have is

Stn ALALAY YOTALA ... 250 files
lat -19.668 -17.258
lon -65.324 -66.147
1961 1.6000 9.8540
.
.
.
18265 rows

Thanks for your help

Last edited by wilelucho; 06-27-2012 at 09:52 AM.
 
Old 06-27-2012, 10:05 AM   #5
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 640

Rep: Reputation: 375Reputation: 375Reputation: 375Reputation: 375
Please use the [CODE] .. [/CODE] tags around your code and data to preserve formatting.
Your command
Code:
$ paste file1.txt file2.txt file3.txt > newfile.txt
should work. Please try it with smaller files and show us what you get, that is contents of file1.txt etc and newfile.txt.
BTW you can supply all 250 files using glob pattern:
Code:
$ paste file*.txt > newfile.txt

Last edited by firstfire; 06-27-2012 at 10:07 AM.
 
1 members found this post helpful.
Old 06-27-2012, 12:21 PM   #6
wilelucho
LQ Newbie
 
Registered: Jun 2012
Location: Brazil
Distribution: Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
All right,
I'm pretty new to this things,

I have
Code:
$ more AGUIRRE.txt
Aguirre
-17.366667
-65.816666
-999.900
-999.900
-999.900
-999.900
-999.900
-999.900
-999.900
-999.900

$ more ALAMOS.txt
Alamos
-18.708334
-65.391663
-999.900
-999.900
-999.900
-999.900
-999.900
-999.900
-999.900
-999.900
-999.900

$more YACUIBA.txt
Yacuiba
-22.016666
-63.700001
0.000
32.000
0.000
45.000
0.000
3.500
0.000
0.000
0.000

Whenever I try
Code:
$ paste AGUIRRE.txt ALAMOS.txt YACUIBA.txt > newfile.txt
I have
Code:
$ more newfile.txt
Aguirre Yacuiba
-17.3666-22.016666
-65.8166-63.700001
-999.9000.000900
-999.90032.00000
-999.9000.000900
-999.90045.00000
-999.9000.000900
-999.9003.500900
-999.9000.000900
-999.9000.000900
-999.9000.000900
Actually I have 250 archives to be added
 
Old 06-27-2012, 01:04 PM   #7
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
I works correctly here (using cut and paste data from your post).

My only GUESS is that the actual files have some extra characters that somehow confuse paste. If you can attach the actual files, we can dig deeper.
 
Old 06-27-2012, 01:12 PM   #8
wilelucho
LQ Newbie
 
Registered: Jun 2012
Location: Brazil
Distribution: Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
All right pixellany,

Attached you will find the three (of 250) files
Attached Files
File Type: txt AGUIRRE.txt (140.7 KB, 1 views)
File Type: txt ALAMOS.txt (152.6 KB, 1 views)
File Type: txt YACUIBA.txt (126.6 KB, 1 views)
 
Old 06-27-2012, 01:49 PM   #9
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729Reputation: 729
bingo!! Those files are in DOS text format---you can use "dos2unix" to convert them.

(I found this by using hexdump (found the DOS 0d+0a sequence (carriage return + newline)---there is probably an easier way)
 
1 members found this post helpful.
Old 06-27-2012, 01:58 PM   #10
wilelucho
LQ Newbie
 
Registered: Jun 2012
Location: Brazil
Distribution: Ubuntu
Posts: 19

Original Poster
Rep: Reputation: Disabled
You nailed it! (I think) I was looking at the same thing, I'm converting my files, I'll yell if something arises

Thanks a lot
 
Old 06-27-2012, 03:05 PM   #11
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,164

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Quote:
Originally Posted by firstfire View Post
BTW you can supply all 250 files using glob pattern:
Code:
$ paste file*.txt > newfile.txt
For testing I created four single-column input files:
Code:
InFile1='/home/daniel/Desktop/LQfiles/dbm408inp1.txt'
InFile2='/home/daniel/Desktop/LQfiles/dbm408inp2.txt'
InFile3='/home/daniel/Desktop/LQfiles/dbm408inp3.txt'
InFile4='/home/daniel/Desktop/LQfiles/dbm408inp4.txt'
This code catenated them side-by-side.
Code:
InFiles='/home/daniel/Desktop/LQfiles/dbm408inp*.txt'
OutFile='/home/daniel/Desktop/LQfiles/dbm408out.txt'
paste -d'\0' $InFiles > $OutFile
Daniel B. Martin
 
  


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
[SOLVED] How to create a single file with size of 50 GB sanjay87 Linux - Server 2 04-18-2012 03:29 PM
[SOLVED] Add a column to a file. Sha_unix Linux - Newbie 9 11-23-2011 05:08 PM
[SOLVED] Need to add a column to a text file Thaidog Programming 2 04-28-2011 10:09 AM
[SOLVED] how to add blank lines whenever the value of a given column alters in a data file? vcmota Programming 9 01-11-2011 09:47 PM
awk multiple column into single column ilukacevic Programming 49 07-19-2010 08:23 PM


All times are GMT -5. The time now is 01:19 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration