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
mcxdeblast(1)							  USER COMMANDS 						     mcxdeblast(1)

  NAME
      mcxdeblast - parse BLAST files and stream output directly into mcl or write mcxassemble input.

  SYNOPSIS
      mcxdeblast file-name

      mcxdeblast  [--score=<b|e|r>  (bit  scores|e-values|normalize  bit score)] [--m9 (expect BLAST column format)] [--out <fname> (output file)]
      [--line-mode abc (write ID1 ID2 score format)] [--sort=<a|o> (alphabetic|occurrence sorting)] [--xi-dat=<suf> (strip <suf> from  file-name)]
      [--xo-dat=<suf>  (add  <suf>  to base name)] [--bcut=<val> (bit score cutoff)] [--ecut=<val> (E-value cutoff)] [--rcut=<val> (raw value cut-
      off)] [--tab=<fname> (tab file)] <file-name>

  DESCRIPTION
      mcxdeblast parses BLAST files.

      In stream mode mcxdeblast output can be directly streamed to mcl by using the mcxdeblast	--line-mode=abc  option  and  equipping  mcl  with
      either --abc or --expect-abc. This can be considered the easy, lightweight and fast track. This functionality was recently acquired by mcl.

      In the classic and slightly more heavy-handed assemble mode, mcxdeblast creates output files suitable for use by mcxassemble. The latter can
      in turn create input suitable for mcl. This is the mode in which mcxdeblast is employed by mclblastline.

  STREAM MODE
      Enter stream mode by specifiying --line-mode=abc.  Use --m9 if the input is in columnar output. Pipe the result to a  file  or  directly	to
      mcl. Example invocations can be found in the mcl manual.

  ASSEMBLE MODE
      If  the input file is named iput, mcxdeblast will by default create files iput.hdr, iput.raw, iput.tab, iput.map, and iput.err. The hdr file
      contains information about the number of nodes found. It will be read by mcxassemble. The raw file contains the co-occurrence scores between
      different  nodes (peptides), also to be read by mcxassemble. The co-occurrence scores are in terms of mcl indentiers, which are subjected to
      rearranging by mcxassemble in order to correctly align them with the tab file.  The tab  file  contains  bindings  between  mcl  identifiers
      (after rearranging as specified in the map file) and the BLAST labels (peptide identifiers). Refer to the manual of mcxassemble for the syn-
      tax of a tab file.  The err file contains a list of any errors encountered.

      If the --tab=fname option is used mcxdeblast changes its behaviour. It will read the file fname, and use the bindings found therein. It will
      no longer output any of the hdr, map, or tab files. The hdr file should be provided by the same application that generated the specified tab
      file, and the map file should no longer be necessary (it might be convenient though and perhaps the future will bring a new --map option).

      The --tab=fname option can be convenient e.g. if you split a BLAST job over multiple machines and want to apply mcxdeblast to  each  of  the
      subresults.  You	do  this by generating a single central tab file in advance.  Then provide each instance of mcxdeblast with this tab file.
      Each instance will generate a raw file. The respective raw files can simply be concatenated and fed to mcxassemble using	its  -raw  option.
      Additionally,  a hdr file has to be specified for mcxassemble using its -hdr option. The syntax of hdr files is described in the mcxassemble
      manual.  Currently there is usually only one variable in the hdr file, which is the number of bindings listed in the tab file. This  number,
      in turn, should equal the total number of different peptides encountered in the BLAST input.

  OPTIONS
      --tab=<fname> (tab file)
	Specify a tab file to use, rather than automatically generating one.

      --out <fname> (output file)
	Specify the name for the output file.

      --score=<b|e|r> (bit scores|e-values|norm bit score)
	Specify whether to use bit scores, E-values, or bit scores normalized by length of the HSP.

      --sort=<a|o> (alphabetic|occurrence sorting)
	Specify how to sort labels.

      --m9 (expect BLAST column format)
	Use this option to parse BLAST output formatted with the -m 9 option.

      --line-mode=abc (write ID1 ID2 SCORE format)
	Use this to stream output directly into mcl. Here abc is a literal; --line-mode may acquire other line output modes.

      --xi-dat=<suf> (strip <suf> from <file-name>)
	If  set, the suffix <suf> is stripped from file-name in order to obtain the base name for output. If <file-name> does not end with suffix,
	it is assumed to be the base name, and <suf> is added in order to obtain the (real) file-name.

      --xo-dat=<suf> (add <suf> to base name)
	Attaches the suffix to the base name. Use this to distinguish between different parses. One might for example use --score=b --bcut=5 --xo-
	dat=b.

      --bcut=<val> (bit score cutoff)
	Bit scores below the cutoff value are ignored. This triggers the output of bit scores and ignores all other values.

      --ecut=<val> (E-value cutoff)
	E-values below the cutoff value are ignored. This triggers the output of E-values and ignores all other values.

      --rcut=<val> (raw value cutoff)
	Raw values below the cutoff value are ignored. This triggers the output of raw values and ignores all other values.

  AUTHOR
      Stijn  van  Dongen.   Jason Stajich implemented the --m9 option.	Abel Ureta-Vidal and Dinakarpandian Deendayal contributed helpful comments
      and fixes.

  SEE ALSO
      mclblastline, mcxassemble, mcl, clmformat.

  mcxdeblast 12-068						      8 Mar 2012						       mcxdeblast(1)
All times are GMT -4. The time now is 06:21 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy