Sponsored Content
Top Forums Shell Programming and Scripting awk Print New Column For Every Two Lines and Match On Multiple Column Values to print another column Post 302874227 by jacobs.smith on Thursday 14th of November 2013 01:05:49 PM
Old 11-14-2013
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

Code:
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 fourth column for every two rows and if

a. Both values are positive, print another column saying z=0,color=pink for both rows.
b. Both values are negative, print another column saying z=0,color=violet for both rows.
c. If first is positive and second is negative, print another column saying z=0,color=yellow for both rows.
d. If first is negative and second is positive, print another column saying z=0,color=brown for both rows.

So, My final output will be

Code:
link1 axis1 0 1 10 z=0,color=pink
link1 axis2 0 1 5 z=0,color=pink
link2 axis1 1 2 -4 z=0,color=violet
link2 axis2 2 3 -3 z=0,color=violet
link3 axis1 3 4 5 z=0,color=yellow
link3 axis2 3 4 -1 z=0,color=yellow
link4 axis1 4 5 -6 z=0,color=brown
link4 axis2 4 5 1 z=0,color=brown

I was able to print the first column as a series but didn't get to know how to make two values the same and at two row intervals.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

how to read the column and print the values under that column

hi all:b:, how to read the column and print the values under that column ...?? file1 have something like this cat file1 ======= column1, column2,date,column3,column4..... 1, 23 , 12/02/2008,...... 2, 45, 14/05/2008,..... 3, 56, 16/03/2008,..... cat file2 =======... (6 Replies)
Discussion started by: gemini106
6 Replies

2. Shell Programming and Scripting

Awk+Grep Input file needs to match a column and print the entire line

I'm having problems since few days ago, and i'm not able to make it works with a simple awk+grep script (or other way to do this). For example, i have a input file1.txt: cat inputfile1.txt 218299910417 1172051195 1172070231 1172073514 1183135117 1183135118 1183135119 1281440202 ... (3 Replies)
Discussion started by: poliver
3 Replies

3. Shell Programming and Scripting

print unique values of a column and sum up the corresponding values in next column

Hi All, I have a file which is having 3 columns as (string string integer) a b 1 x y 2 p k 5 y y 4 ..... ..... Question: I want get the unique value of column 2 in a sorted way(on column 2) and the sum of the 3rd column of the corresponding rows. e.g the above file should return the... (6 Replies)
Discussion started by: amigarus
6 Replies

4. Shell Programming and Scripting

find expression with awk in only one column, and if it fits, print whole column

Hi. How do I find an expression with awk in only one column, and if it fits, then print that whole column. 1 apple oranges 2 bannanas pears 3 cats dogs 4 hesaid shesaid echo "which number:" read NUMBER (user inputs number 2 for this example) awk " /$NUMBER/ {field to search is field... (2 Replies)
Discussion started by: glev2005
2 Replies

5. Shell Programming and Scripting

awk strings search + print next column after match

Hi, I have a file filled with search strings which have a blank in between and look like this: S. g. Ehr. o. Jg. v. d. Chijs g. Ehr. Now i would like to search for the strings and it also shall return the next column after the match. awk -v FILE="search_strings.txt" 'BEGIN {... (10 Replies)
Discussion started by: sdf
10 Replies

6. Shell Programming and Scripting

awk command to print only selected rows in a particular column specified by column name

Dear All, I have a data file input.csv like below. (Only five column shown here for example.) Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 3,2,4,5,6 5,3,5,5,6 From this I want the below output Data1,StepNo,Data2,Data3,Data4 2,1,3,4,5 3,1,5,6,7 where the second column... (4 Replies)
Discussion started by: ks_reddy
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

Based on column in file1, find match in file2 and print matching lines

file1: file2: I need to find matches for any lines in file1 that appear in file2. Desired output is '>' plus the file1 term, followed by the line after the match in file2 (so the title is a little misleading): This is honestly beyond what I can do without spending the whole night on it, so I'm... (2 Replies)
Discussion started by: pathunkathunk
2 Replies

9. Shell Programming and Scripting

Awk: print lines with one of multiple pattern in the same field (column)

Hi all, I am new to using awk and am quickly discovering what a powerful pattern-recognition tool it is. However, I have what seems like a fairly basic task that I just can't figure out how to perform in one line. I want awk to find and print all the lines in which one of multiple patterns (e.g.... (8 Replies)
Discussion started by: elgo4
8 Replies

10. Shell Programming and Scripting

Need awk or Shell script to compare Column-1 of two different CSV files and print if column-1 matche

Example: I have files in below format file 1: zxc,133,joe@example.com cst,222,xyz@example1.com File 2 Contains: hxd hcd jws zxc cst File 1 has 50000 lines and file 2 has around 30000 lines : Expected Output has to be : hxd hcd jws (5 Replies)
Discussion started by: TestPractice
5 Replies
funinfoget(3)							SAORD Documentation						     funinfoget(3)

NAME
FunInfoGet - get information from Funtools struct SYNOPSIS
#include <funtools.h> int FunInfoGet(Fun fun, int type, char *addr, ...) DESCRIPTION
The FunInfoGet() routine returns information culled from the Funtools structure. The first argument is the Fun handle from which informa- tion is to be retrieved. This first required argument is followed by a variable length list of pairs of arguments. Each pair consists of an integer representing the type of information to retrieve and the address where the information is to be stored. The list is terminated by a 0. The routine returns the number of get actions performed. The full list of available information is described below. Please note that only a few of these will be useful to most application devel- opers. For imaging applications, the most important types are: FUN_SECT_DIM1 int /* dim1 for section */ FUN_SECT_DIM2 int /* dim2 for section */ FUN_SECT_BITPIX int /* bitpix for section */ These would be used to determine the dimensions and data type of image data retrieved using the FunImageGet() routine. For example: /* extract and bin the data section into an image buffer */ buf = FunImageGet(fun, NULL, NULL); /* get required information from funtools structure. this should come after the FunImageGet() call, in case the call changed sect_bitpix */ FunInfoGet(fun, FUN_SECT_BITPIX, &bitpix, FUN_SECT_DIM1, &dim1, FUN_SECT_DIM2, &dim2, 0); /* loop through pixels and reset values below limit to value */ for(i=0; i<dim1*dim2; i++){ switch(bitpix){ case 8: if( cbuf[i] <= blimit ) cbuf[i] = bvalue; ... } It is important to bear in mind that the call to FunImageGet() can change the value of FUN_SECT_BITPIX (e.g. if "bitpix=n" is passed in the param list). Therefore, a call to FunInfoGet() should be made after the call to FunImageGet(), in order to retrieve the updated bitpix value. See the imblank example code for more details. It also can be useful to retrieve the World Coordinate System information from the Funtools structure. Funtools uses the the WCS Library developed by Doug Mink at SAO, which is available here. (More information about the WCSTools project in general can be found here.) The FunOpen() routine initializes two WCS structures that can be used with this WCS Library. Applications can retrieve either of these two WCS structures using FunInfoGet(): FUN_WCS struct WorldCoor * /* wcs structure, for image coordinates*/ FUN_WCS0 struct WorldCoor * /* wcs structure, for physical coordinates */ The structure retrieved by FUN_WCS is a WCS library handle containing parameters suitable for use with image coordinates, regardless of whether the data are images or tables. For this structure, the WCS reference point (CRPIX) has been converted to image coordinates if the underlying file is a table (and therefore in physical coordinates). You therefore must ensure that the positions being passed to a routine like pix2wcs are in image coordinates. The FUN_WCS0 structure has not had its WCS reference point converted to image coordinates. It there- fore is useful when passing processing physical coordinates from a table. Once a WCS structure has been retrieved, it can be used as the first argument to the WCS library routines. (If the structure is NULL, no WCS information was contained in the file.) The two important WCS routines that Funtools uses are: #include <wcs.h&gt void pix2wcs (wcs,xpix,ypix,xpos,ypos) struct WorldCoor *wcs; /* World coordinate system structure */ double xpix,ypix; /* x and y coordinates in pixels */ double *xpos,*ypos; /* RA and Dec in degrees (returned) */ which converts pixel coordinates to sky coordinates, and: void wcs2pix (wcs, xpos, ypos, xpix, ypix, offscl) struct WorldCoor *wcs; /* World coordinate system structure */ double xpos,ypos; /* World coordinates in degrees */ double *xpix,*ypix; /* coordinates in pixels */ int *offscl; /* 0 if within bounds, else off scale */ which converts sky coordinates to pixel coordinates. Again, please note that the wcs structure returned by FUN_WCS assumes that image coor- dinates are passed to the pix2wcs routine, while FUN_WCS0 assumes that physical coordinates are passed. Note that funtools.h file automatically includes wcs.h. An example program that utilizes these WCS structure to call WCS Library routines is twcs.c. The following is the complete list of information that can be returned: name type comment --------- -------- --------------------------------------------- FUN_FNAME char * /* file name */ FUN_GIO GIO /* gio handle */ FUN_HEADER FITSHead /* fitsy header struct */ FUN_TYPE int /* TY_TABLE,TY_IMAGE,TY_EVENTS,TY_ARRAY */ FUN_BITPIX int /* bits/pixel in file */ FUN_MIN1 int /* tlmin of axis1 -- tables */ FUN_MAX1 int /* tlmax of axis1 -- tables */ FUN_MIN2 int /* tlmin of axis2 -- tables */ FUN_MAX2 int /* tlmax of axis2 -- tables */ FUN_DIM1 int /* dimension of axis1 */ FUN_DIM2 int /* dimension of axis2 */ FUN_ENDIAN int /* 0=little, 1=big endian */ FUN_FILTER char * /* supplied filter */ FUN_IFUN FITSHead /* pointer to reference header */ FUN_IFUN0 FITSHead /* same as above, but no reset performed */ /* image information */ FUN_DTYPE int /* data type for images */ FUN_DLEN int /* length of image in bytes */ FUN_DPAD int /* padding to end of extension */ FUN_DOBLANK int /* was blank keyword defined? */ FUN_BLANK int /* value for blank */ FUN_SCALED int /* was bscale/bzero defined? */ FUN_BSCALE double /* bscale value */ FUN_BZERO double /* bzero value */ /* table information */ FUN_NROWS int /* number of rows in file (naxis2) */ FUN_ROWSIZE int /* size of user row struct */ FUN_BINCOLS char * /* specified binning columns */ FUN_OVERFLOW int /* overflow detected during binning? */ /* array information */ FUN_SKIP int /* bytes to skip in array header */ /* section information */ FUN_SECT_X0 int /* low dim1 value of section */ FUN_SECT_X1 int /* hi dim1 value of section */ FUN_SECT_Y0 int /* low dim2 value of section */ FUN_SECT_Y1 int /* hi dim2 value of section */ FUN_SECT_BLOCK int /* section block factor */ FUN_SECT_BTYPE int /* 's' (sum), 'a' (average) for binning */ FUN_SECT_DIM1 int /* dim1 for section */ FUN_SECT_DIM2 int /* dim2 for section */ FUN_SECT_BITPIX int /* bitpix for section */ FUN_SECT_DTYPE int /* data type for section */ FUN_RAWBUF char * /* pointer to raw row buffer */ FUN_RAWSIZE int /* byte size of raw row records */ /* column information */ FUN_NCOL int /* number of row columns defined */ FUN_COLS FunCol /* array of row columns */ /* WCS information */ FUN_WCS struct WorldCoor * /* wcs structure, converted for images*/ FUN_WCS0 struct WorldCoor * /* wcs structure, not converted */ Row applications would not normally need any of this information. An example of how these values can be used in more complex programs is the evnext example code. In this program, the time value for each row is changed to be the value of the succeeding row. The program thus reads the time values for a batch of rows, changes the time values to be the value for the succeeding row, and then merges these changed time values back with the other columns to the output file. It then reads the next batch, etc. This does not work for the last row read in each batch, since there is no succeeding row until the next batch is read. Therefore, the pro- gram saves that last row until it has read the next batch, then processes the former before starting on the new batch. In order to merge the last row successfully, the code uses FUN_RAWBUF to save and restore the raw input data associated with each batch of rows. Clearly, this requires some information about how funtools works internally. We are happy to help you write such programs as the need arises. SEE ALSO
See funtools(7) for a list of Funtools help pages version 1.4.2 January 2, 2008 funinfoget(3)
All times are GMT -4. The time now is 04:59 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy