awk -- print combinations for 2 cols


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk -- print combinations for 2 cols
# 1  
Old 03-17-2011
awk -- print combinations for 2 cols

Dear all, could you please help me with awk please?
I have such input:
Code:
Input:
a d
b e
c f

The number of lines is unknown before reading the file.

I need to print possible combination between the two columns like this:
Code:
Output:
a d
b d
c d
a e
b e
c e
a f
b f
c f

Thank you!!!
# 2  
Old 03-17-2011
Code:
nawk 'FNR==NR{a[$1];next}{for(i in a) print i, $2}' myFile myFile

This User Gave Thanks to vgersh99 For This Post:
# 3  
Old 03-17-2011
ah... the same file twice. super! thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Print a python script down a list in a text file without printing a lot combinations

In a python script I have 2 files printing side by side on the same line. I want to have 1 of the files to be already displayed at once while the other file print down the list in the file and it still will produce new lines. I want to do it like that to reduce printing a lot of lines and... (0 Replies)
Discussion started by: bigvito19
0 Replies

2. Shell Programming and Scripting

awk permutations and combinations

hello, I'm reading this thread, in which there is this code :awk ' function comb(v,i) { for(i in A) { delete A; if(length(A)) comb((v?v"+":x)i) else print v"+"i A; } } { A } END { comb(); } ' infilebut I can't understand where does v come... (5 Replies)
Discussion started by: daPeach
5 Replies

3. UNIX for Dummies Questions & Answers

Generating all possible combinations of values in field 1 (awk)

Input: A|1 B|2 C|3 D|4 Output: A+B|3 A+C|4 A+D|5 B+C|5 B+D|6 C+D|7 A+B+C|6 A+B+D|7 A+C+D|8 B+C+D|9 A+B+C+D|10 I only managed to get the output for pairs of $1 values (i.e. combination of length 2): (4 Replies)
Discussion started by: beca123456
4 Replies

4. Shell Programming and Scripting

Creating all possible bi-combinations of a list with grep/awk

I have a 1-column file such as the example below: flower cat dog pizza car book I want to create a second column in which all possible 2-item combinations of column one are outputted in 2 tab-separated columns, such as: flower flower cat flower dog flower pizza ... (5 Replies)
Discussion started by: owwow14
5 Replies

5. Shell Programming and Scripting

Bitwise comparison of cols

Hello, I want to compute the bitwise number of matches in pairwise fashion for all columns. The problem is I have 18486955 rows and 750 columns. Please help with code, I believe this will take a lot of time, is there a way of tracking progress? Input Org1 Org2 Org3 A A T A ... (9 Replies)
Discussion started by: ritakadm
9 Replies

6. Shell Programming and Scripting

Print combinations of alphabets in a sequence

Hi Friends, I have a series of alphabets like this AGCAA The values inside the square brace indicate that either of them can be present at that position. And those ones without a brace, means that they are the only ones that could be printed at that location. Now, I would like to know... (5 Replies)
Discussion started by: jacobs.smith
5 Replies

7. Shell Programming and Scripting

Grouping matches by cols

Dear all I have a large file w. ~ 10 million lines. The first two cols have matching partners. For example: A A A B B B or A A B A B B The matches may be separated by an unknown number of lines. My intention is to group them and add a "group" value in the last col. For... (12 Replies)
Discussion started by: gbalsu
12 Replies

8. Shell Programming and Scripting

Printing all combinations : Awk

$ cat key.txt #ID1 Start 1|AA1 2|AA2 3|AA3 4|AA4 #ID1 Complete #ID2 Start 1|BB1 2|BB2 3|BB3 #ID2 Complete I was required this output: AA1|BB1 AA1|BB2 AA1|BB3 (7 Replies)
Discussion started by: jkl_jkl
7 Replies

9. Shell Programming and Scripting

awk - print formatted without knowing no of cols

Hi, i want to print(f) the content of a file, but i don't know how many columns it has (i.e. it changes from each time my script is run). The number of columns is constant throughout the file. Any suggestions? (8 Replies)
Discussion started by: bistru
8 Replies

10. Shell Programming and Scripting

Awk execution with more combinations..

The requirement is to extract 9 fields randomly from a 13 field CSV file to make another CSV file. While doing that, the field 7 and 8 of input csv file should comeout as field 7 of output with the value as first charecters of both 7 and 8 fields of input file(CSV file). Presently I am using... (1 Reply)
Discussion started by: mitte_dino
1 Replies
Login or Register to Ask a Question