Sponsored Content
Top Forums Shell Programming and Scripting Match columns and print specific field Post 302924203 by Pushpraj on Friday 7th of November 2014 01:06:26 AM
Old 11-07-2014
Match columns and print specific field

Hello,

I have data in following format.
Code:
pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate,rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx,hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot,cli_abrt,srv_abrt,

main,FRONTEND,,,0,3,15000,61,13752,14647,0,0,1,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,12,,,,0,60,0,1,0,0,,0,12,61,,,
apache2,elb0,0,0,0,1,,3,687,723,,0,,0,0,0,0,UP,1,1,0,0,0,45,0,,1,2,1,,3,,2,0,,1,L4OK,,0,0,3,0,0,0,0,0,,,,0,0,
apache2,elb1,0,0,0,1,,3,687,723,,0,,0,0,0,0,UP,1,1,0,0,0,45,0,,1,2,2,,3,,2,0,,1,L4OK,,0,0,3,0,0,0,0,0,,,,0,0,
apache2,elb2,0,0,0,1,,3,687,723,,0,,0,0,0,0,UP,1,1,0,0,0,45,0,,1,2,3,,3,,2,0,,1,L4OK,,0,0,3,0,0,0,0,0,,,,0,0,
apache2,elb3,0,0,0,1,,3,687,723,,0,,0,0,0,0,UP,1,1,0,0,0,45,0,,1,2,4,,3,,2,0,,1,L4OK,,0,0,3,0,0,0,0,0,,,,0,0,
apache2,elb4,0,0,0,1,,3,687,723,,0,,0,0,0,0,UP,1,1,0,0,0,45,0,,1,2,5,,3,,2,0,,1,L4OK,,0,0,3,0,0,0,0,0,,,,0,0,
apache2,BACKEND,0,0,0,3,0,60,13752,14460,0,0,,0,0,0,0,UP,24,24,0,,0,45,0,,1,2,0,,60,,1,0,,12,,,,0,60,0,0,0,0,,,,,0,0,

Now I want to print "slim" value for "main,FRONTEND" or "ereq" value for "apache2,elb4" or process data in similar fashion. I tried below command but it prints entire column.
Code:
#awk -F, '/main,FRONTEND/{print}' socat.txt

it prints entire line which has around 51 fields, among that one value carries "slim" field value.I dont know field number of "slim". I want to print "slim" value of "main,FRONTEND" column. Giving field number to awk can work but since there are lots of fields and elbs I dont want to use that option.

Thanks,
Pushpraj

Last edited by Franklin52; 11-07-2014 at 06:59 AM.. Reason: Please use code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Print last occurrence if first field match

Hi All, I have an input below. If the term in the 1st column is equal, print the last row which 1st column is equal.In the below example, it's " 0001 k= 27 " and " 0004 k= 6 " (depicted in bold). Those terms in 1st column which are not repetitive are to be printed as well. Can any body help me... (9 Replies)
Discussion started by: Raynon
9 Replies

2. Shell Programming and Scripting

Script to Match first field of two Files and print

Hi, I want to get script or command in Sun Unix which matches first fields of both the files and print the feilds of one files, example may make it more clear. InputFile1 ================== Alex,1,fgh Menthos,45454,toto Gothica,855,ee Zenie4,77,gg Salvatore,66,oo Dhin,1234,papapa... (3 Replies)
Discussion started by: indian.ace
3 Replies

3. Shell Programming and Scripting

Match and print columns in second file

Hi All, I have to match each row in file 1 with 1st row in file 2 and print the corresponding column from file2. I am trying to use an awk script to do this. For example cat File1 X1 X3 X4 cat File2 ID X1 X2 X3 X4 A 1 6 2 1 B 2 7 3 3 C 3 8 4 1 D 4 9 1 1 (3 Replies)
Discussion started by: newpro
3 Replies

4. UNIX for Dummies Questions & Answers

Match columns and write specific word

Hi all I have another question as of now. I have two files One file contain data like this Serendipity glamerus Shenpurity In another file these entries are present in different columns like this from 2 column onwards SRN Serendipity Non serendipity ... (1 Reply)
Discussion started by: Priyanka Chopra
1 Replies

5. UNIX for Dummies Questions & Answers

How to match on phrase at beginning of line and specific columns?

Here is my file: 700 7912345678910 61234567891234567891 700 8012345678910 61234567891234567891 I want to pull all lines that begin with '700' only if columns 11-12 are '79'. My code so far only pulls the '79', not the whole line: grep ^700 file1 | cut -c 11,12 |... (7 Replies)
Discussion started by: Scottie1954
7 Replies

6. Shell Programming and Scripting

Match two columns from two files and print output

Hello, I have two files which are of the following format File 1 which has two columns Protein_ID Substitution NP_997239 T53R NP_060668 V267M NP_058515 P856A NP_001206 T55M NP_006601 D371Y ... (2 Replies)
Discussion started by: nans
2 Replies

7. Shell Programming and Scripting

How to print with awk specific field different from specific character?

Hello, i need help with awk. I have this file: cat number DirB port 67 er_enc_out 0 er_bad_os 0 DirB port 71 er_enc_out 56 er_bad_os 0 DirB port 74 er_enc_out 0 er_bad_os 0 DirB port 75 ... (4 Replies)
Discussion started by: elilmal
4 Replies

8. UNIX for Advanced & Expert Users

Match and print based on columns

HI, I have 2 different questions in this thread. Consider 2 files as input (input file have different line count ) File 1 1 1 625 56 1 12 657 34 1 9 25 45 1 2 20 54 67 3 25 35 27 4 45 73 36 5 125 56 45 File2 1 1 878 76 1 9 83 67 2 20 73 78 4 47 22 17 3 25 67 99 (4 Replies)
Discussion started by: rossi
4 Replies

9. Shell Programming and Scripting

Command/script to match a field and print the next field of each line in a file.

Hello, I have a text file in the below format: Source Destination State Lag Status CQA02W2K12pl:D:\CAQA ... (10 Replies)
Discussion started by: pocodot
10 Replies

10. Shell Programming and Scripting

awk to print text in field if match and range is met

In the awk below I am trying to match the value in $4 of file1 with the split value from $4 in file2. I store the value of $4 in file1 in A and the split value (using the _ for the split) in array. I then strore the value in $2 as min, the value in $3 as max, and the value in $1 as chr. If A is... (6 Replies)
Discussion started by: cmccabe
6 Replies
MEMSET_S(3)						   BSD Library Functions Manual 					       MEMSET_S(3)

NAME
memset_s -- copy a value to all bytes of a memory buffer LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#define __STDC_WANT_LIB_EXT1__ 1 #include <string.h> errno_t memset_s(void *s, rsize_t smax, int c, rsize_t n); DESCRIPTION
The memset_s() function copies the value c (converted to an unsigned char) into each of the first n bytes of the memory buffer whose starting address is given by s. It is a runtime-constraints violation if s is a null pointer, or if either of smax or n is larger than RSIZE_MAX, or if smax is smaller than n. If there is a runtime-constraints violation, and if s is not a null pointer, and if smax is not larger than RSIZE_MAX, then, before reporting the runtime-constraints violation, memset_s() copies smax bytes to the destination. In contrast to the memset(3) function, calls to memset_s() will never be ``optimised away'' by a compiler. This property is required by the following sentences in section K.3.7.4.1 of ISO/IEC 9899:2011 (``ISO C11''): Unlike memset(), any call to the memset_s() function shall be evaluated strictly according to the rules of the abstract machine as described in (5.1.2.3). That is, any call to the memset_s() function shall assume that the memory indicated by s and n may be accessi- ble in the future and thus must contain the values indicated by c. RETURN VALUES
The memset_s() function returns zero for success, or a non-zero error code if there was a runtime-constraints violation. ERRORS
memset_s() returns the following error codes. It does not store the error code in the global errno variable: [EINVAL] The s argument was a null pointer. [E2BIG] One or both of smax or n was larger than RSIZE_MAX. [EOVERFLOW] n was larger than smax. SEE ALSO
memset(3). STANDARDS
The memset_s() function conforms to ISO/IEC 9899:2011 (``ISO C11''), except that the set_constraint_handler_s() interface is not supported. BSD
February 21, 2012 BSD
All times are GMT -4. The time now is 07:28 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy