Three space delimited files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Three space delimited files
# 1  
Old 06-22-2011
Three space delimited files

So I have three space delimited files. Each have 90 rows and many columns. I want to merge them by columns. I use paste to merge file 1 and file2 or file 3 and it works. But when I try to merge file 2 and file 3 using paste or merge or cat, I cannot merge them by column, instead they are merged by row. I cannot figure out why, why doesn't it work even though they have the same number of rows? Smilie
# 2  
Old 06-22-2011
I can't tell what you did from this description. Could you show us what you actually typed?

paste works because it's meant to connect lines column by column like that. cat just reads files one by one. I have no 'merge' command at all and don't know what it is.
This User Gave Thanks to Corona688 For This Post:
# 3  
Old 06-22-2011
I used paste 1a.txt 2a.txt > 3.txt

1a.txt contains 90 rows and 2a.txt contains 90 rows as well. But when I use the above function, I get a file with 180 rows. So the paste function does not merge by column, it merges by row.
# 4  
Old 06-22-2011
the paste command does merge column by column. Paste this into your terminal.

Code:
# create file1
cat <<EOF >file1
a
b
c
d
EOF

# create file2
cat <<EOF >file2
g
h
i
j
EOF

# create file3
cat <<EOF >file3
k
l
m
n
EOF

# combine them into text with 4 rows and 3 columns.  It will print to the terminal.
paste file1 file2 file3

Code:
a       g       k
b       h       l
c       i       m
d       j       n

If paste doesn't paste columns there's something wrong with how you're using it. You also mentioned something about cat and merge but gave no further indication of what you did with them.

Didn't you say you had three input files? You're giving it two. If 3.txt was supposed to be an input file, you just overwrite it with garbage.

Code:
paste inputfile1 inputfile2 inputfile3 > outputfile

If it still doesn't work, show us what you actually typed, word for word, letter for letter, keystroke for keystroke. Use screenshots if necessary.
This User Gave Thanks to Corona688 For This Post:
# 5  
Old 06-22-2011
Ok, thanks. It actually worked. I realized that the files were indeed merged column by column.

However there is another issue. I want each row to correspond to a single line, now it splits rows into two lines. How do I format the file so that each row corresponds to a single line? Thanks a lot and sorry for the confusion! Smilie
# 6  
Old 06-22-2011
I don't suppose any of those input files were edited with notepad? the extra carriage returns Windows fills everything with will make them do weird things when used with UNIX commands.
This User Gave Thanks to Corona688 For This Post:
# 7  
Old 06-22-2011
Quote:
Originally Posted by Corona688
I don't suppose any of those input files were edited with notepad? the extra carriage returns Windows fills everything with will make them do weird things when used with UNIX commands.
They might have been. The files were given to me by someone. Is there a way to fix it?
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

Space delimited variables

I have a shell script where I am using space delimited variables. Var=" ${var} data1 table1 " Var=" ${var} data2 table2 " Var=" ${var} data3 table3 " Var=" ${var} data4 table4 " I am using a single variable to store multiple values so I can use them in for loop. Each value contains space in... (1 Reply)
Discussion started by: srilaxman
1 Replies

2. Shell Programming and Scripting

Help/Advise please for converting space delimited string variable to comma delimited with quote

Hi, I am wanting to create a script that will construct a SQL statement based on a a space delimited string that it read from a config file. Example of the SQL will be For example, it will read a string like "AAA BBB CCC" and assign to a variable named IN_STRING. I then concatenate... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Remove space before numbers in delimited file

Hi, I have a file which looks like this FORD|1333-1| 10000100010203| 100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 I need the output to look like this FORD|1333-1|10000100010203|100040507697|0002|356.45|5555| SSSSY|KKKKM|1000005|10| N096|10043| C987 The leading... (8 Replies)
Discussion started by: wahi80
8 Replies

4. Shell Programming and Scripting

How to make tab delimited file to space delimited?

Hi How to make tab delimited file to space delimited? in put file: ABC kgy jkh ghj ash kjl o/p file: ABC kgy jkh ghj ash kjl Use code tags, thanks. (1 Reply)
Discussion started by: jagdishrout
1 Replies

5. Shell Programming and Scripting

Need a script to convert comma delimited files to semi colon delimited

Hi All, I need a unix script to convert .csv files to .skv files (changing a comma delimited file to a semi colon delimited file). I am a unix newbie and so don't know where to start. The script will be scheduled using cron and needs to convert each .csv file in a particular folder to a .skv... (4 Replies)
Discussion started by: CarpKing
4 Replies

6. UNIX for Dummies Questions & Answers

Changing only the first space to a tab in a space delimited text file

Hi, I have a space delimited text file but I only want to change the first space to a tab and keep the rest of the spaces intact. How do I go about doing that? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

7. Shell Programming and Scripting

How to convert a space delimited file into a pipe delimited file using shellscript?

Hi All, I have space delimited file similar to the one as shown below.. I need to convert it as a pipe delimited, the values inside the pipe delimited file should be as highlighted... AA ATIU2345098809 009697 005374 BB ATIU2345097809 005445 006518 CC ATIU9685098809 003215 003571 DD... (7 Replies)
Discussion started by: nithins007
7 Replies

8. UNIX for Dummies Questions & Answers

Combining three space delimited files by column

I have three space delimited files, how do I combine them by column in Unix? Thanks! (3 Replies)
Discussion started by: evelibertine
3 Replies

9. Shell Programming and Scripting

Merging files into a single tab delimited file with a space separating

I have a folder that contains say 50 files in a sequential order: cdf_1.txt cdf_2.txt cdf_3.txt cdf_3.txt . . . cdf_50.txt. I need to merge these files in the same order into a single tab delimited file. I used the following shell script: for x in {1..50}; do cat cdf_${x}.txt >>... (3 Replies)
Discussion started by: Lucky Ali
3 Replies

10. UNIX for Dummies Questions & Answers

Converting Space delimited file to Tab delimited file

Hi all, I have a file with single white space delimited values, I want to convert them to a tab delimited file. I tried sed, tr ... but nothing is working. Thanks, Rajeevan D (16 Replies)
Discussion started by: jeevs81
16 Replies
Login or Register to Ask a Question