add columns from file to another and sort


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting add columns from file to another and sort
# 8  
Old 12-12-2007
hi,

i can't use paste because in the FILEB there's more line then FILEA so if i sort the two file and do paste i will not get the result.
can u help me to loop this problem with shell script to paste every info in each correspond line and after that i sort this file by columns (info columns).

thanks
# 9  
Old 12-12-2007
Quote:
Originally Posted by kamel.seg
hi,

i can't use paste because in the FILEB there's more line then FILEA so if i sort the two file and do paste i will not get the result.
can u help me to loop this problem with shell script to paste every info in each correspond line and after that i sort this file by columns (info columns).

thanks
Well can you show a sample of the contents of fileA and fileB?
# 10  
Old 12-12-2007
Sample of FILEA :


comp, PASS
sim, FAILED
UF, PASS
promo, FAILED
xy, PASS
bad, PASS
bad_12, PASS
bridge_AD, FAILED
sim_V3 PASS
split_LSF, PASS
multiple, FAILED

and FILEB

comp, PASS
sim, test_sim
UF, data_uf
promo, data_uf
bad, test_bad
split_LSF, groupe_lsf
multiple, groupe_test

thanks
# 11  
Old 12-12-2007
Quote:
Originally Posted by kamel.seg
Sample of FILEA :


comp, PASS
sim, FAILED
UF, PASS
promo, FAILED
xy, PASS
bad, PASS
bad_12, PASS
bridge_AD, FAILED
sim_V3 PASS
split_LSF, PASS
multiple, FAILED

and FILEB

comp, PASS
sim, test_sim
UF, data_uf
promo, data_uf
bad, test_bad
split_LSF, groupe_lsf
multiple, groupe_test

thanks
And what is the expected output based on the sample contents of fileA and fileB?
# 12  
Old 12-12-2007
Sample of FILEA :


comp, PASS
sim, FAILED
UF, PASS
promo, FAILED
xy, PASS
bad, PASS
bad_12, PASS
bridge_AD, FAILED
sim_V3 PASS
split_LSF, PASS
multiple, FAILED

and FILEB

comp, groupe1
sim, test_sim
UF, data_uf
promo, data_uf
bad, test_bad
split_LSF, groupe_lsf
multiple, groupe_test

the excepted output is
FILEA:

comp, groupe1
sim, FAILED test_sim
UF, PASS data_uf
promo, FAILED data_uf
xy, PASS test_bad
bad, PASS
bad_12, PASS
bridge_AD, FAILED
sim_V3 PASS
split_LSF, PASS groupe_lsf
multiple, FAILED groupe_test


thanks
# 13  
Old 12-12-2007
Quote:
Originally Posted by kamel.seg
Sample of FILEA :


comp, PASS
sim, FAILED
UF, PASS
promo, FAILED
xy, PASS
bad, PASS
bad_12, PASS
bridge_AD, FAILED
sim_V3 PASS
split_LSF, PASS
multiple, FAILED

and FILEB

comp, groupe1
sim, test_sim
UF, data_uf
promo, data_uf
bad, test_bad
split_LSF, groupe_lsf
multiple, groupe_test

the excepted output is
FILEA:

comp, groupe1
sim, FAILED test_sim
UF, PASS data_uf
promo, FAILED data_uf
xy, PASS test_bad
bad, PASS
bad_12, PASS
bridge_AD, FAILED
sim_V3 PASS
split_LSF, PASS groupe_lsf
multiple, FAILED groupe_test


thanks
Code:
sort -t"," -k1,1 fileA > FILEA
sort -t"," -k1,1 fileB > FILEB
join -t"," -1 1 -2 1 -a 1 -o 1.1 1.2 2.2 FILEA FILEB > output.txt

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Seperated by columns, merge in a file, sort them on common column

Hi All, I have 4 files in below format. I took them as an example. File 1: Cut from position 1-4 then 6-7 then 8-14 then rest left and make them as columns in one new file. Inserting character H to the initial of all line like HCTOT. CTOT 456787897 Low fever CTOR 556712345 High fever... (2 Replies)
Discussion started by: Mannu2525
2 Replies

2. Shell Programming and Scripting

How to sort a text file if certain columns are blank?

Dear all, I am trying to sort a text file based on column 3, 10, 11 and 12. But certain column are blank for some lines. Column 3 has to be in ascending order after sorting. Part of my input file is as follows: CN727990 1 A01 4703 5083 73.28 - A_scaffold000011 4365605 4365985 73.28 +... (10 Replies)
Discussion started by: huiyee1
10 Replies

3. Web Development

Sort 3 or more columns in a HTML file

Hi Friends, I have a HTMl file with 10 columns. I found a script online that can sort any single column in a HTML file. But, I would like to sort on multiple columns at once. Could you please show some pointers? Thanks (6 Replies)
Discussion started by: jacobs.smith
6 Replies

4. Shell Programming and Scripting

sort second columns in file.

File will have two columns key column and second column which is pipe separated and that need to be sorted. Below is input file. 1, D|B|A|C 2, C|A|B 3, E|A|F|G|H|D|B|C 4, A|B|D|C|F Output should be 1, A|B|C|D 2, A|B|C 3, A|B|C|D|E|F|G|H 4, A|B|D|C|F (11 Replies)
Discussion started by: girish119d
11 Replies

5. Shell Programming and Scripting

Add columns in the begin of the file

Hello Guys I need your kind help to solve the below issue I have an Flat file Format like CONCAT_KEY|FCTR_LVL_CD|RNWL_NS_CD|RTG_PLN_YR_CD 0000000000000010006100001001500005020071001|0|1|61 0000000000000010006100001003000010020071001|0|1|61 I want to add two column with default... (3 Replies)
Discussion started by: Pratik4891
3 Replies

6. Shell Programming and Scripting

Add columns in csv file

Hi everybody, I am new here and I need a reel help please A have a csv file and I want to add new in the end of the file Devisce Model,VMGuest Name,Host OS Name, Memory Size Value1,Value2,Value3,Value4 Value5,Value6,Value7,Value8 Value9,Value10,Value11,Value12 And I want to add to new... (3 Replies)
Discussion started by: villebonnais
3 Replies

7. Shell Programming and Scripting

How to sort columns in excel(csv) file

i want sort columns with headers based on another file headers file1 eg: i'm having an empty file with only coumn names like lastname firstname title expirydate stlcno status etc... another file with same column names and some other as well but in different order... file2 eg:firstname... (2 Replies)
Discussion started by: Man83Nagesh
2 Replies

8. UNIX for Dummies Questions & Answers

Sort file using 2 columns

Hi, I am trying to sort a file first by the string column, then by the number column. file: xyz1 2 xyzX 4 xyz2 1 xyz13 3 xyz11 5 xyz13 10 xyz1 1 xyz10 1 xyz4 2 result should be xyz1 1 xyz1 2 ... (3 Replies)
Discussion started by: fargo
3 Replies

9. UNIX for Dummies Questions & Answers

Add a header to a sort file instruction

Hello, I have a header which I have to add to a sorted file, however if I use cat header sortedfile > newfile, the operation takes 2 minutes as the sorted file is over 400mb. I have noticed that when I sort the 400mb unsorted file, this only takes 14 seconds to create the output. As... (2 Replies)
Discussion started by: clarcombe
2 Replies

10. UNIX for Dummies Questions & Answers

Help needed to sort multiple columns in one file

Hi, I would like to know given that I have 3 columns. Let say I have first 3 columns to do operation and these operation output is printed out each line by line using AWK and associative array.Currently in the output file, I do a sort by -r for the operation output. The problem comes to... (1 Reply)
Discussion started by: ahjiefreak
1 Replies
Login or Register to Ask a Question