Sponsored Content
Top Forums Shell Programming and Scripting Creating all possible bi-combinations of a list with grep/awk Post 302900548 by owwow14 on Wednesday 7th of May 2014 12:21:28 PM
Old 05-07-2014
Creating all possible bi-combinations of a list with grep/awk

I have a 1-column file such as the example below:

Code:
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:

Code:
flower    flower
cat    flower
dog     flower
pizza     flower
car     flower
book     flower
flower     cat
cat     cat
dog     cat
pizza     cat
car     cat
book     cat
flower    dog
cat    dog
dog    dog
pizza    dog
car    dog
book    dog
flower    pizza
cat    pizza
dog    pizza
pizza    pizza
car    pizza
book    pizza
flower    car
cat    car
dog    car
pizza    car
car    car
book    car
flower    book
cat    book
dog    book
pizza    book
car    book
book    book

Is there a
Code:
grep / awk

that allows me to do this?
Thanks
 

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

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

3. UNIX for Dummies Questions & Answers

Creating a one liner with wget, grep and mv

I have the following simplified script, that consists of a download (wget), a grab of only the lines with a comma (grep) and a rename of the file to indicate its date of origin (mv): wget http://www.example.com/datafile.csv grep ',' datafile.csv mv datafile.csv datafile.`date... (2 Replies)
Discussion started by: figaro
2 Replies

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

5. UNIX for Dummies Questions & Answers

Creating a column based list from a string list

I have a string containing fields separated by space Example set sr="Fred Ted Joe Peter Paul Jean Chris Tim Tex" and want to display it in a column format, for example to a maximum of a window of 100 characters And hopefully display some thing like Fred Ted Joe ... (3 Replies)
Discussion started by: kristinu
3 Replies

6. UNIX for Dummies Questions & Answers

Creating a two column list of date pairs form a single column list

Hi all, looking for some help here. I'm what you'd call a dirty programmer. my shell scripts might be ugly, but they (usually) function... Say I have a single column text file with a list of dates (yyyymmdd) that represent the elevation of a point on that date (I work with land subsidence, so... (2 Replies)
Discussion started by: jbrandt1979
2 Replies

7. OS X (Apple)

Having trouble creating an alias for grep

Hi, I'm using Mac 10.9.1. I would like to create an alias for grep so that it won't print out messages like "grep: /Users/davea/workspace/myproject/subdir/: Is a directory" all the time. So in my terminal, I opened ~/.profile and entered alias grep='grep -s' However, when I close and... (5 Replies)
Discussion started by: laredotornado
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
ONEKO(6)							   Games Manual 							  ONEKO(6)

NAME oneko - Creates a cute cat chasing around your mouse cursor.
SYNOPSIS
oneko [-help] [-tora] [-dog] [-sakura] [-tomoyo] [-time n] [-speed n] [-idle n] [-name name] [-towindow] [-toname name] [-tofocus] [-posi- tion geometry] [-rv] [-noshape] [-fg] [-bg] DESCRIPTION
oneko changes your mouse cursor into mouse and creates a little cute cat and the cat start chasing around your mouse cursor. If the cat catchup the ``mouse'', start sleeping. Options -help Prints help message on usage. -tora Make cat into "tora-neko", a cat wite tiger-like stripe. -dog Runs a dog instead of a cat. -sakura Runs Sakura Kinomoto instead of a cat. -tomoyo Runs Tomoyo Daidouji instead of a cat. -time interval Sets interval timer which determine intervals for cat animation. Default value is 125000 and unit is micro-second. Smaller value makes cat run faster. -speed distance Specify the distance where cat jumps at one move in dot resolution. Default is 16. -idle speed Specify the threshold of the speed which ``mouse'' running away to wake cat up. -name name Specify the window name of cat. -towindow When oneko starts with this option, you must select a window by cursor. Then cat appears and starts chasing the window instead of mouse. You can select another running oneko as the target window. If root window is selected, cat chases mouse as usually. When the target window is not in sight and not closed, cat chases mouse as usually. If the target window is closed, this program exit. -toname name Specify the window name of target to make cat chase it instead of mouse. You can specify another running oneko as the target win- dow. When the target window is not in sight and not closed, cat chases mouse as usually. If the target window is closed, this pro- gram exit. -tofocus Makes cat run to and on top of focus window. When focus window is not in sight, cat chases mouse as usually. -position geometry Specify X and Y offsets in pixels to adjust position of cat relative to mouse pointer. -rv Reverse background color and foreground color. -noshape Don't use SHAPE extension. -fg color Foreground color. -bg color Background color. -cursor cursornumber Specify a cursos number to set when quitting. For example, 132 is the default root cursor. Resources Application name is "neko"(or "tora") and class name is "Oneko". tora Set ``True'' if you want "tora-neko". time Sets interval timer in micro-second. speed Sets distance to jump in pixel. idle Sets speed threshold to wake cat up when ``mouse'' running away. noshape Set ``True'' if you don't want to use SHAPE extension. reverse Set ``True'' if you want to switch foreground and background color. foreground Foreground color. background Background color. Notes While this program uses XGetDefault, be sure to use "neko.resouce" form. If you run this program as "tora", by hard of soft link, the -tora option is enabled by default. BSD Daemon Copyright 1988 by Marshall Kirk McKusick. All Rights Reserved. Sakura Kinomoto and Tomoyo Daidouji are characters in a comic strip "CARDCAPTOR SAKURA" (CLAMP, Kodansha), with the sanction indicated in CLAMP SCHOOL WEB CAMPUS (http://www.clamp.f-2.co.jp/). AUTHOR
Original xneko is written by Masayuki Koba and modified to oneko by Tatsuya Kato, and modified furthermore by John Lerchey, Eric Anderson, Toshihiro Kanda and Kiichiroh Mukose. MAINTAINER
Send questions or problems to mukose@hbar.mp.es.osaka-u.ac.jp ONEKO(6)
All times are GMT -4. The time now is 02:58 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy