Sponsored Content
Top Forums Shell Programming and Scripting Printing all combinations : Awk Post 302200105 by aigles on Wednesday 28th of May 2008 12:01:27 PM
Old 05-28-2008
Try the following script :
Code:
$ cat comb.sh
awk '
{
   file_count++;
   rec_num = 0;
   while (getline rec <$0)
     records[file_count, ++rec_num] = rec;
   close($0);
   records[file_count, "count"] = rec_num;
}

function comb_file(file_num, rec     ,rec_count ,r) {
   if (file_num > file_count) {
      print rec;
   } else {
      rec_count = records[file_num, "count"];
      for (r=1; r<=rec_count; r++)
         comb_file(file_num+1, rec (file_num>1 ? "|" : "") records[file_num, r]);
   }
}

END {
   rec = "";
   comb_file(1, rec);
}

' file_order.txt
$

Input files:
Code:
$ cat file_order.txt
file_1.txt
file_2.txt
file_3.txt
$ cat file_1.txt
F1.1
F1.2
F1.3
$ cat file_2.txt
F2.1
F2.2
$ cat file_3.txt
F3.1
F3.2
F3.3
F3.4
$

Output :
Code:
$ comb.sh
F1.1|F2.1|F3.1
F1.1|F2.1|F3.2
F1.1|F2.1|F3.3
F1.1|F2.1|F3.4
F1.1|F2.2|F3.1
F1.1|F2.2|F3.2
F1.1|F2.2|F3.3
F1.1|F2.2|F3.4
F1.2|F2.1|F3.1
F1.2|F2.1|F3.2
F1.2|F2.1|F3.3
F1.2|F2.1|F3.4
F1.2|F2.2|F3.1
F1.2|F2.2|F3.2
F1.2|F2.2|F3.3
F1.2|F2.2|F3.4
F1.3|F2.1|F3.1
F1.3|F2.1|F3.2
F1.3|F2.1|F3.3
F1.3|F2.1|F3.4
F1.3|F2.2|F3.1
F1.3|F2.2|F3.2
F1.3|F2.2|F3.3
F1.3|F2.2|F3.4
$

Jean-Pierre.
 

10 More Discussions You Might Find Interesting

1. 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

2. Shell Programming and Scripting

AWK printing

Hello, I am trying to write a formatted report into a file using .ksh script and awk. Here is the command I am trying to run echo "before awk" ${SRC_SCHEMA} echo | awk '{printf "%-20s", ${SRC_SCHEMA} }' >>$REPORT_SQL_NAME I get the following error before awk ADW awk: 0602-562 Field $()... (1 Reply)
Discussion started by: fastgoon
1 Replies

3. Shell Programming and Scripting

AWK printing

i have a file containing a line 123456 is it possible to use AWK to print it out to look like 1 2 3 4 5 6 (8 Replies)
Discussion started by: tomjones
8 Replies

4. Shell Programming and Scripting

Awk printing help

Hallo, i have a file which looks like this: $1 $2 $3 Student1 55 Pass 55 Pass 35 Fail Student2 55 Pass 55 Pass 35 Fail i want that the $1 field... (3 Replies)
Discussion started by: saint2006
3 Replies

5. Shell Programming and Scripting

awk -- print combinations for 2 cols

Dear all, could you please help me with awk please? I have such input: 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: Output: a d b d c d a e b e c e a f (2 Replies)
Discussion started by: irrevocabile
2 Replies

6. Shell Programming and Scripting

Printing using awk

Hi I am relatively new to awk so i am getting confused a lot I am in need of help ... I am trying to append coloumns to the end of line using AWK I tried using this command awk -F "," '{for(s=7;s<=217;s++);$s="0";}1' OFS=, sam_sri_out It is giving me an output like this...... (1 Reply)
Discussion started by: Sri3001
1 Replies

7. 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

8. 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

9. 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

10. 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
set_color(1)							       fish							      set_color(1)

NAME
set_color - set_color - set the terminal color set_color - set the terminal color Synopsis set_color [-v --version] [-h --help] [-b --background COLOR] [COLOR] Description Change the foreground and/or background color of the terminal. COLOR is one of black, red, green, brown, yellow, blue, magenta, purple, cyan, white and normal. o -b, --background Set the background color o -c, --print-colors Prints a list of all valid color names o -h, --help Display help message and exit o -o, --bold Set bold or extra bright mode o -u, --underline Set underlined mode o -v, --version Display version and exit Calling set_color normal will set the terminal color to whatever is the default color of the terminal. Some terminals use the --bold escape sequence to switch to a brighter color set. On such terminals, set_color white will result in a grey font color, while set_color --bold white will result in a white font color. Not all terminal emulators support all these features. This is not a bug in set_color but a missing feature in the terminal emulator. set_color uses the terminfo database to look up how to change terminal colors on whatever terminal is in use. Some systems have old and incomplete terminfo databases, and may lack color information for terminals that support it. Download and install the latest version of ncurses and recompile fish against it in order to fix this issue. Version 1.23.1 Sun Jan 8 2012 set_color(1)
All times are GMT -4. The time now is 08:31 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy