Sponsored Content
Top Forums Shell Programming and Scripting awk command to print only selected rows in a particular column specified by column name Post 302695091 by ks_reddy on Saturday 1st of September 2012 09:55:25 AM
Old 09-01-2012
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.)
Code:
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
Code:
Data1,StepNo,Data2,Data3,Data4
2,1,3,4,5
3,1,5,6,7

where the second column StepNo contents are '1'.
I used the below simple script to get this output.
Code:
awk -F, '$2==1' input.csv

But many times the second column is not always StepNo as there are many versions of input files with varying column positions and total number of columns.
So I need a script(with awk) to get my required output by specifying column name instead of referring from column number .

Thanks in advance.
Sidda
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

flags to suppress column output, # of rows selected in db2 sql in UNIX

Hello, I am new to db2 SQL in unix so bear with me while I try to explain the situation. I have a text file that has the contents of the where condition that I am using for a db2 SQL in UNIX ksh. Here is the snippet. if ; then echo "Begin processing VALUEs" ... (1 Reply)
Discussion started by: jerardfjay
1 Replies

2. Shell Programming and Scripting

print selected rows with awk

Hi everybody: Could anybody tell me how I can print from a file a selected rows with awk. In my case I only want print in another file all the rows from NR=8 to NR=2459 and the increment each 8 times. I tried to this: awk '{for (i=8; i=2459; i+=8); NR==i}' file1 > file2 But doesn't... (6 Replies)
Discussion started by: tonet
6 Replies

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

4. Shell Programming and Scripting

Awk to add selected row column data

Looks at the most efficient way to add up the column of data based off of the rows. Random data Name-Number-ID Sarah-2.0-15 Bob-6.3-15 Sally-1.0-10 James-1.0-10 Scotty-10.7-15 So I would select all those who have ID = 15 and then add up total number read - p "Enter ID number" Num ... (3 Replies)
Discussion started by: Ironguru
3 Replies

5. Shell Programming and Scripting

Please Help!!!! Awk for summing columns based on selected column value

a,b,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii a thru ii are digits and strings.... The awk needed....if coloumn 9 == i (coloumn 9 is string ), output the sum of x's(coloumn 22 ) in all records and sum of y's (coloumn 23 ) in all records in a file (records.txt).... (6 Replies)
Discussion started by: BrownBob
6 Replies

6. UNIX for Dummies Questions & Answers

Print rows with substring in column

Hi I want to print all rows where there is the alphabet N in the 6th column as a substring. Here is what i tried and not working.Please help ! awk ' { if ( $6 == *"N"* ) print $0} ' awk ' { if ( "${6}" == *N* ) print $0} ' awk ' { if( grep -q N <<<$6) print $0} ' (1 Reply)
Discussion started by: newbie83
1 Replies

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

8. Shell Programming and Scripting

Print column details from fixed width file using awk command

hi, i have a fixed width file with multiple columns and need to print data using awk command. i use: awk -F "|" '($5 == BH) {print $1,$2,$3}' <non_AIM target>.txt for a delimiter file. but now i have a fixed width file like below: 7518 8269511BH 20141224951050N8262 11148 8269511BH... (5 Replies)
Discussion started by: kcdg859
5 Replies

9. Shell Programming and Scripting

Combine multiple rows based on selected column keys

Hello I want to collapse a file with multiple rows into consolidated lines of entries based on selected columns as the 'key'. Example: 1 2 3 Abc def ghi 1 2 3 jkl mno p qrts 6 9 0 mno def Abc 7 8 4 Abc mno mno abc 7 8 9 mno mno abc 7 8 9 mno j k So if columns 1, 2 and 3 are... (6 Replies)
Discussion started by: linuxlearner123
6 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
LP(4)							   BSD Kernel Interfaces Manual 						     LP(4)

NAME
lp -- printer port Internet Protocol driver SYNOPSIS
ifconfig plip0 myaddress hisaddress [-link0] device ppbus device plip device ppc DESCRIPTION
The lp driver allows a PC parallel printer port to be used as a point-to-point network interface between two similarly configured systems. Data is transferred 4 bits at a time, using the printer status lines for input: hence there is no requirement for special bidirectional hard- ware and any standard AT-compatible printer port with working interrupts may be used. During the boot process, for each plip device which is probed and has an interrupt assigned, a corresponding network device is created. Configuring an lp device with ifconfig(8) causes the corresponding parallel port bus to be reserved for PLIP until the network interface is configured 'down'. The communication protocol is selected by the link0 flag: -link0 (default) Use FreeBSD mode (LPIP). This is the simpler of the two modes and therefore slightly more efficient. link0 Use Crynwr/Linux compatible mode (CLPIP). This mode has a simulated Ethernet packet header, and is easier to interface to other types of equipment. The interface MTU defaults to 1500, but may be set to any value. Both ends of the link must be configured with the same MTU. Cable Connections The cable connecting the two parallel ports should be wired as follows: Pin Pin Description 2 15 Data0 -> ERROR* 3 13 Data1 -> SLCT 4 12 Data2 -> PE 5 10 Data3 -> ACK* 6 11 Data4 -> BUSY 15 2 ERROR* -> Data0 13 3 SLCT -> Data1 12 4 PE -> Data2 10 5 ACK* -> Data3 11 6 BUSY -> Data4 18-25 18-25 Ground Cables with this wiring are widely available as 'Laplink' cables, and are often coloured yellow. The connections are symmetric, and provide 5 lines in each direction (four data plus one handshake). The two modes use the same wiring, but make a different choice of which line to use as handshake. FreeBSD LPIP mode The signal lines are used as follows: Data0 (Pin 2) Data out, bit 0. Data1 (Pin 3) Data out, bit 1. Data2 (Pin 4) Data out, bit 2. Data3 (Pin 5) Handshake out. Data4 (Pin 6) Data out, bit 3. ERROR* (pin 15) Data in, bit 0. SLCT (pin 13) Data in, bit 1. PE (pin 12) Data in, bit 2. BUSY (pin 11) Data in, bit 3. ACK* (pin 10) Handshake in. When idle, all data lines are at zero. Each byte is signalled in four steps: sender writes the 4 most significant bits and raises the hand- shake line; receiver reads the 4 bits and raises its handshake to acknowledge; sender places the 4 least significant bits on the data lines and lowers the handshake; receiver reads the data and lowers its handshake. The packet format has a two-byte header, comprising the fixed values 0x08, 0x00, immediately followed by the IP header and data. The start of a packet is indicated by simply signalling the first byte of the header. The end of the packet is indicated by inverting the data lines (i.e., writing the ones-complement of the previous nibble to be transmitted) without changing the state of the handshake. Note that the end-of-packet marker assumes that the handshake signal and the data-out bits can be written in a single instruction - otherwise certain byte values in the packet data would falsely be interpreted as end-of-packet. This is not a problem for the PC printer port, but requires care when implementing this protocol on other equipment. Crynwr/Linux CLPIP mode The signal lines are used as follows: Data0 (Pin 2) Data out, bit 0. Data1 (Pin 3) Data out, bit 1. Data2 (Pin 4) Data out, bit 2. Data3 (Pin 5) Data out, bit 3. Data4 (Pin 6) Handshake out. ERROR* (pin 15) Data in, bit 0. SLCT (pin 13) Data in, bit 1. PE (pin 12) Data in, bit 2. ACK* (pin 10) Data in, bit 3. BUSY (pin 11) Handshake in. When idle, all data lines are at zero. Each byte is signalled in four steps: sender writes the 4 least significant bits and raises the hand- shake line; receiver reads the 4 bits and raises its handshake to acknowledge; sender places the 4 most significant bits on the data lines and lowers the handshake; receiver reads the data and lowers its handshake. [Note that this is the opposite nibble order to LPIP mode]. Packet format is: Length (least significant byte) Length (most significant byte) 12 bytes of supposed MAC addresses (ignored by FreeBSD). Fixed byte 0x08 Fixed byte 0x00 <IP datagram> Checksum byte. The length includes the 14 header bytes, but not the length bytes themselves nor the checksum byte. The checksum is a simple arithmetic sum of all the bytes (again, including the header but not checksum or length bytes). FreeBSD calculates outgoing checksums, but does not validate incoming ones. The start of packet has to be signalled specially, since the line chosen for handshake-in cannot be used to generate an interrupt. The sender writes the value 0x08 to the data lines, and waits for the receiver to respond by writing 0x01 to its data lines. The sender then starts signalling the first byte of the packet (the length byte). End of packet is deduced from the packet length and is not signalled specially (although the data lines are restored to the zero, idle state to avoid spuriously indicating the start of the next packet). SEE ALSO
ppbus(4), ppc(4), ifconfig(8) BUGS
Busy-waiting loops are used while handshaking bytes, (and worse still when waiting for the receiving system to respond to an interrupt for the start of a packet). Hence a fast system talking to a slow one will consume excessive amounts of CPU. This is unavoidable in the case of CLPIP mode due to the choice of handshake lines; it could theoretically be improved in the case of LPIP mode. Polling timeouts are controlled by counting loop iterations rather than timers, and so are dependent on CPU speed. This is somewhat sta- bilised by the need to perform (slow) ISA bus cycles to actually read the port. BSD
March 4, 1996 BSD
All times are GMT -4. The time now is 11:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy