Combine columns from many files but keep them aligned in columns-shorter left column issue
Hello everyone,
I searched the forum looking for answers to this but I could not pinpoint exactly what I need as I keep having trouble.
I have many files each having two columns and hundreds of rows.
first column is a string (can have many words) and the second column is a number.The files are tab separated.
Example of some rows of three files:
file1.txt
file2.txt
file3.txt
I want to to combine the files into one.
I use the following code for the time being:
The problem is that the first file in the file is smaller than the other ones and the output, when the rows of the first file end gets misaligned.
The columns of the second file shift to the left, and all the others follow etc.
I have many files and this is getting very confusing for the users, who are biologists and do not want to manipulate datasets. When there is a shorter left column the right columns become missaligned.
This is an example output that shows the problem: the problem starts at the line that i show as <----problem. the column I CVS IP should be the third column but it shifts to second.
.......
When the lines from the firs file end all utput is shifted to the left. How can I keep them aligned?
i looked everywhere and I have not been able to find out how to solve it.
I am not entirely familiar with awk, i use perl for my other scripting and i am a beginner in shell scripting.
Many thanks for your help in advance
Last edited by vbe; 11-30-2012 at 09:49 AM..
Reason: use also code tags for your data, it keeps the format...
Thank you so much. This is working and aligning the columns correctly!
If you have time, can youvery very briefly explain how it works, why your for statements manage to align the columns, especially what happens at the printf? for (j=1;j<=m;j++) {
for (i=0;i<fc;i++) {
printf (a[i,j])? (a[i,j] "\t"):("\t\t");
awk seems to be a very powerful language for file manipulation. How did you learn it? Textbook or website?
Again, thank you so much.
Right now my input to this code file*.txt > out.xls
outputs the files pasted together but the files are pasted randomly. I want to read the files from my folder alphabetical lexicographical order and paste them together.
is there a way to sort my input files alphabetically before I run this code?
I tried sort file*.txt but it doesnt work, nor does ls-1|folder.
Hello,
This post is already here but want to do this with another way
Merge multiples files with multiples duplicates keys by filling "NULL" the void columns for anothers joinning files
file1.csv:
1|abc
1|def
2|ghi
2|jkl
3|mno
3|pqr
file2.csv:
1|123|jojo
1|NULL|bibi... (2 Replies)
I have two files, file1 and file2 who have identical number of rows and columns. However, the script is supposed to be used for for different files and I cannot know the format in advance. Also, the number of columns changes within the file, some rows have more and some less columns (they are... (13 Replies)
Hi all, I'm pretty much a newbie to UNIX. I would appreciate any help with UNIX coding on comparing two large csv files (greater than 10 GB in size), and output a file with matching columns.
I want to compare file1 and file2 by 'id' and 'chain' columns, then extract exact matching rows'... (5 Replies)
I have two text files that look something like this:
A:B:C 123
D:E:F 234
G:H:I 345
J:K:L 123
M:N:O 456
P:Q:R 567
A:B:C 456
D:E:F 567
G:H:I 678
J:K:L 456
M:N:O 789
P:Q:R 890
I want to find the line where the first column matches and then combine the second columns into a single... (8 Replies)
This may seem obvious but I am having problems doing this as columns get converted to rows when i try to write a script.
I have 2 files text1.txt and text2.txt each of which have 6 columns of numbers separated by a space.
I need to combine the 2 files so that the output file text3.txt maintains... (2 Replies)
Hi Guys,
I want to combine 2 files and and put together in 1 file and make two columns out it. See below desired output. Any help will be much appreciated.
inputfile1.txt
12345
67890
24580
inputfile2.txt
AAAAA
BBBBB
CCCCC (11 Replies)
Hi All
I'm running a shell script and the output is something like:
Col1 Col2 Col3
aaaa aaaaaaa aaaaa
bbbbb bbbbb bbbbbb
ccc cccccc ccccccc
But I require the output to printed as given below:
Col1 Col2 Col3
aaaa ... (4 Replies)