Sponsored Content
Top Forums UNIX for Beginners Questions & Answers If pattern in column 3 matches pattern in column 2 (any row), print value in column 1 Post 303035828 by bleedingturnip on Tuesday 4th of June 2019 09:23:38 AM
Old 06-04-2019
If pattern in column 3 matches pattern in column 2 (any row), print value in column 1

Hi all,

I have searched and searched, but I have not found a solution that quite fits what I am trying to do.

I have a long list of data in three columns. Below is a sample:

Code:
1,10,8
2,12,10
3,13,12
4,14,14
5,15,16
6,16,18

Moderator's Comments:
Mod Comment Please use code tags

What I need to do is as follows: If a number in column three matches a number in column two, print "," and the number in the corresponding row in column one. If there is no match, just print ",". So an expected result for the sample would be as follows:

Code:
1,10,8,
2,12,10,1
3,13,12,2
4,14,14,4
5,15,16,6
6,16,18,

I've assumed that AWK would be the best tool for this task, but I am open to using any tool. The solutions I have found and tried only match corresponding rows. They don't match a pattern in one column to any pattern in another column. I'm guessing a loop may be required, but I am a novice to looping.

The values in column one are just the ordinal numbers for the rows, if that is relevant to a solution.

I am very grateful for any help. Thank you.

Last edited by jim mcnamara; 06-04-2019 at 10:30 AM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

replace a column in a file if it matches certain pattern

Hi, I want to replace a column in a file if it matches certain pattern. Can you help me on this. Here is the file content. 000000 1111111 2222222 011111 0123445 1234556 023445 1111111 2343455 if second column contains 1111111 i need to replace it with 0000000 Can you... (6 Replies)
Discussion started by: Krrishv
6 Replies

2. Shell Programming and Scripting

column to row conversion with additional pattern

Hi there, I've an input file1 as follows: 1001 1002 1003 1004 1005 I would like to have an output file2 as follows: Numbers are 1001/ 1002/ 1003/ 1004/ 1005/ Any help is appreciated. (2 Replies)
Discussion started by: kbirde
2 Replies

3. Shell Programming and Scripting

need to remove duplicates based on key in first column and pattern in last column

Given a file such as this I need to remove the duplicates. 00060011 PAUL BOWSTEIN ad_waq3_921_20100826_010517.txt 00060011 PAUL BOWSTEIN ad_waq3_921_20100827_010528.txt 0624-01 RUT CORPORATION ad_sade3_10_20100827_010528.txt 0624-01 RUT CORPORATION ... (13 Replies)
Discussion started by: script_op2a
13 Replies

4. Shell Programming and Scripting

Replace column that matches specific pattern, with column data from another file

Can anyone please help with this? I have 2 files as given below. If 2nd column of file1 has pattern foo1@a, find the matching 1st column in file2 & replace 2nd column of file1 with file2's value. file1 abc_1 foo1@a .... abc_1 soo2@a ... def_2 soo2@a .... def_2 foo1@a ........ (7 Replies)
Discussion started by: prashali
7 Replies

5. Shell Programming and Scripting

Row to column transpose between same pattern.

Hi All, I have been trying to transpose rows to column in an large file (about 15000 lines) between matching pattern. Searched all posts in this forum, but not able find the solution to my problem. Any help appreciated.!! Input /*------XXXXXX-------*/ owner: XXXX location: XXXX... (3 Replies)
Discussion started by: RobP
3 Replies

6. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 Replies

7. Shell Programming and Scripting

Print every 5 4th column values as separate row with different first column

Hi, I have the following file, chr1 100 200 20 chr1 201 300 22 chr1 220 345 23 chr1 230 456 33.5 chr1 243 567 90 chr1 345 600 20 chr1 430 619 21.78 chr1 870 910 112.3 chr1 914 920 12 chr1 930 999 13 My output would be peak1 20 22 23 33.5 90 peak2 20 21.78 112.3 12 13 Here the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

8. Shell Programming and Scripting

Difference of the same column when two other column matches and one column differs less than 1 hour

This is my input file : # cat list 20130430121600, cucm, location,76,2 20130430121600,cucm1,location1,76,4 20130430122000,cucm,location,80,8 20130430122000,cucm1,location1,90,8 20130430140000,cucm1,location1,87,11 20130430140000, cucm,location,67,9 This is the required output ... (1 Reply)
Discussion started by: Lakshmikumari
1 Replies

9. Shell Programming and Scripting

awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column

Hi, My input files is like this axis1 0 1 10 axis2 0 1 5 axis1 1 2 -4 axis2 2 3 -3 axis1 3 4 5 axis2 3 4 -1 axis1 4 5 -6 axis2 4 5 1 Now, these are my following tasks 1. Print a first column for every two rows that has the same value followed by a string. 2. Match on the... (3 Replies)
Discussion started by: jacobs.smith
3 Replies

10. Shell Programming and Scripting

Remove entire line from a file if 1st column matches a pattern

I have one requirement to delete all lines from a file if it matches below scenario. File contains three column. Employee Number, Employee Name and Employee ID Scenario is: delete all line if Employee Number (1st column) contains below 1. Non-numeric Employee Number 2. Employee Number that... (3 Replies)
Discussion started by: anshu ranjan
3 Replies
vsynth(1Vi)															       vsynth(1Vi)

NAME
vsynth - synthesize an image SYNOPSIS
vsynth -pattern pattern [-option ...] [outfile] DESCRIPTION
vsynth creates a one-band image with a specified size, pixel representation, and pattern of pixel values. The program knows how to create several different types of patterns. These are described below under PATTERNS. COMMAND LINE OPTIONS
vsynth accepts the following options in addition to those described below under PATTERNS. -help Prints a message describing options. -out outfile Specifies where the synthesized image is to be written as a Vista data file. -pattern pattern Specifies, with one of the keywords listed below, the type of pattern to be used to set pixel values. -nrows nrows and -ncolumns ncolumns Specify the size of the synthesized image. Default: 256 rows and columns. -repn bit | ubyte | sbyte | short | long | float | double Specifies the pixel representation of the synthesized image. Default: float. -name name Specifies the name to be given the synthesized image. Default: ``image''. The output file can be specified on the command line or allowed to default to the standard output stream. PATTERNS
The -pattern option specifies which of the following patterns is used to initialized pixel values. For each type of pattern there are addi- tional options that may be used to specify pattern parameters. In general, numeric parameters are not restricted to just integer values. Constant -pattern constant [-base b] Default: 0. All pixel values are set to b. Impulse -pattern impulse [-amplitude a] Default: 1. [-base b] Default: 0. [-origin i j] Default: image center. The pixel at row i, column j is set to a; all others are set to b. (i and j are truncated to integers.) Ramp -pattern ramp [-amplitude a] Default: 1. [-base b] Default: 0. [-origin i j] Default: image center. [-orientation d] Default: 0. The image is filled with a ramp whose slope is a units per pixel. The ramp is centered at row i, column j, where it has the value b. The ramp increases in the direction d, which is measured CCW in degrees from the direction of increasing column number. Sine Grating -pattern sine [-amplitude a] Default: 1. [-base b] Default: 0. [-origin i j] Default: image center. [-phase w] Default: 0. and one of [-frequency f] Default: 0. [-orientation d] Default: 0. or [-period t] Default: 8. [-orientation d] Default: 0. or [-xfreq x] Default: 0. [-yfreq y] Default: 0. The image is filled with a sine grating. The grating has a DC component of b and an amplitude of a (or 2a peak-to-peak). Its fre- quency and direction may be specified by any of three combinations of frequency (in cycles per pixel, measured either in the direc- tion of the grating or as horizontal and vertical components), period (in pixels per cycle), and orientation (in degrees CCW from the direction of increasing column number). The grating is shifted so that at row i, column j it has phase w radians. Zone Plate -pattern zone [-amplitude a] Default: 1. [-base b] Default: 0. [-origin i j] Default: image center. [-period t] Default: 8. [-phase w] Default: 0. The image is filled with the zone plate pattern defined by f(r) = a cos(r^2/t + w) + b, where r is the radial distance from the ori- gin at row i, column j. Uniformly Distributed Noise -pattern uniform [-amplitude a] Default: 1. [-base b] Default: 1. [-seed s] Default: a random number. Pixels are set to random values drawn independently from [b,b+a] according to a uniform distribution. The random number generator is initialized with the seed s. Normally Distributed Noise -pattern normal [-amplitude a] Default: 1. [-base b] Default: 1. [-seed s] Default: a random number. Pixel values are set to random values drawn independently according to a normal (Gaussian) distribution with mean b and standard deviation a. The random number generator is initialized with the seed s. Binomially Distributed Noise -pattern binomial [-amplitude a] Default: 1. [-base b] Default: 1. [-density p] Default: 0.5. [-seed s] Default: a random number. Pixel values are drawn at random from a binomial distribution. A pixel is given the value b with probability 1 -p, and it is given the value b+a with probability p. SEE ALSO
VImage(3Vi), Vista(7Vi) AUTHOR
Art Pope <pope@cs.ubc.ca> Vista Version 1.12 31 March 1994 vsynth(1Vi)
All times are GMT -4. The time now is 09:02 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy