Paste many files with different row number in one file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Paste many files with different row number in one file
# 1  
Old 03-03-2014
Paste many files with different row number in one file

Hi everybody
I am trying to merge many files in one files using paste or pr command but I am not able to resolve this issue.
The file are tab delimited like these:
Code:
1    4721519    4723118
1    5022468    5024918
1    7093519    7098118

Code:
2    19736573    19741172
2    21907973    21910572
2    22915182    22920279
2    22927075    22928479

Code:
3    5201000    5204399
3    6950250    6951199
3    7416800    7418599
3    7514200    7516799
3    8147000    8148799

The problem consist in maintening the columns separated after paste command, like this;
Code:
1    4721519    4723118    2    19736573    19741172    3    5201000    5204399
1    5022468    5024918    2    21907973    21910572    3    6950250    6951199
1    7093519    7098118    2    22915182    22920279    3    7416800    7418599
            2    22927075    22928479    3    7514200    7516799
                        3    8147000    8148799

The paste command does not work for me
Code:
paste file1 file2 > file3

or
Code:
 paste -d'\t' file1 file2 > file3

because my ouput is like that:
Code:
1    4721519    4723118    2    19736573    19741172    3    5201000    5204399
1    5022468    5024918    2    21907973    21910572    3    6950250    6951199
1    7093519    7098118    2    22915182    22920279    3    7416800    7418599
    2    22927075    22928479    3    7514200    7516799
            3    8147000    8148799

do you have any ideas?

Thank you
# 2  
Old 03-03-2014
pr seems to do the job quite well, I don't see the problem. The files are nicely alingned, separated by tabs:
Code:
$ pr -m -t file1 file2 file3
1    4721519    4723118 2    19736573    197411 3    5201000    5204399
1    5022468    5024918 2    21907973    219105 3    6950250    6951199
1    7093519    7098118 2    22915182    229202 3    7416800    7418599
                        2    22927075    229284 3    7514200    7516799
                                                3    8147000    8148799

Edit: nevermind, I forgot about the tabs in the input file...
# 3  
Old 03-03-2014
Hi,
You must give all file to one step, example with your 3 files input (and ';' either '\t' to show):
Code:
$ paste -d';' file1 file2 file3
1    4721519    4723118;2    19736573    19741172;3    5201000    5204399
1    5022468    5024918;2    21907973    21910572;3    6950250    6951199
1    7093519    7098118;2    22915182    22920279;3    7416800    7418599
;2    22927075    22928479;3    7514200    7516799
;;3    8147000    8148799

We can see that field is respected.

Regards.
# 4  
Old 03-03-2014
try running strings on the files first and/or use a different formatting options...like piping the output to awk or use printf
# 5  
Old 03-03-2014
Hi all
with my files neither paste or pr seems to work..
Because maybe is a formatting error I will give you some of my files.
Could you try please to use these files?

Best
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Select and copy .csv files based on row and column number

Dear UNIX experts, I'm a command line novice working on a Macintosh computer (Bash shell) and have neither found advice that is pertinent to my problem on the internet nor in this forum. I have hundreds of .csv files in a directory. Now I would like to copy the subset of files that contains... (8 Replies)
Discussion started by: rcsapo
8 Replies

2. Shell Programming and Scripting

Read row number from 1 file and print that row of second file

Hi. How can I read row number from one file and print that corresponding record present at that row in another file. eg file1 1 3 5 7 9 file2 11111 22222 33333 44444 55555 66666 77777 88888 99999 (3 Replies)
Discussion started by: Abhiraj Singh
3 Replies

3. Shell Programming and Scripting

Get row number from file1 and print that row of file2

Hi. How can we print those rows of file2 which are mentioned in file1. first character of file1 is a row number.. for eg file1 1:abc 3:ghi 6:pqr file2 a abc b def c ghi d jkl e mno f pqr ... (6 Replies)
Discussion started by: Abhiraj Singh
6 Replies

4. UNIX for Dummies Questions & Answers

Finding row number along with length of row

I have a fixed length file and I want to find out row number along with row length. I have a program that give me the line length if it satisfy the condition; but i would like to add row number as well? How do I do that? while IFS= read -r line; do if ; then echo ${line} echo... (8 Replies)
Discussion started by: princetd001
8 Replies

5. Shell Programming and Scripting

How to count number of files in directory and write to new file with number of files and their name?

Hi! I just want to count number of files in a directory, and write to new text file, with number of files and their name output should look like this,, assume that below one is a new file created by script Number of files in directory = 25 1. a.txt 2. abc.txt 3. asd.dat... (20 Replies)
Discussion started by: Akshay Hegde
20 Replies

6. Shell Programming and Scripting

Using paste command every nth number of file

Hi, I want to use paste command in a loop that does it every 6 files. My sample files are like the ones below. 20010101.txt 20010106.txt 20010111.txt 20010116.txt 20010121.txt 20010126.txt 20010131.txt 20010205.txt 20010210.txt 20010215.txt 20010220.txt 20010225.txt 20010302.txt... (4 Replies)
Discussion started by: ida1215
4 Replies

7. Shell Programming and Scripting

The difference between end number in the early row and the start number in the next

Hi Power User, I'm trying to compute this kind of text file format: file1: jakarta 100 150 jakarta 170 210 beijing 220 250 beijing 260 280 beijing 290 320 new_york 330 350 new_york 370 420 tokyo 430 470 tokyo 480 ... (2 Replies)
Discussion started by: anjas
2 Replies

8. Shell Programming and Scripting

Paste second columns from files to its corresponding file

Hi All, I have two sets of files. One set with extension .txt This set has file names with numbers like these. 1.txt, 2.txt, 3.txt until extactly 100.txt. The .txt files look like these: 0.38701788 93750 0.38622013 94456 0.38350296 94440 0.38282126 94057 0.38282126 94439 0.35847232... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

9. UNIX for Dummies Questions & Answers

How do you delete cells from a space delimited text file given row and column number?

How do you delete cells from a space delimited text file given row and column number? Letś say the row number is r and the column number is c. Thanks! (5 Replies)
Discussion started by: evelibertine
5 Replies

10. Shell Programming and Scripting

removing files with certain number in the first row

Hello! I have 32000 files in a directory and want to remove those with first row beging with 0.00; file names are in numbers from 1 through 32000; I have coded the following but it gives me error: while ( i <= 32000 ) if (head -1 $i ==0.00) rm $i end Well, i am sure even if this... (14 Replies)
Discussion started by: nxp
14 Replies
Login or Register to Ask a Question