Sponsored Content
Top Forums Shell Programming and Scripting Awk, appending a number in the first column of a row with a condition Post 302923926 by RavinderSingh13 on Wednesday 5th of November 2014 08:10:05 AM
Old 11-05-2014
Hello hayreter,

Following may help you in same.

Code:
awk '/<\/event>/ {print $0;next} /\<event\>/ {print $0;A++;next} !/^$/{print A OFS $0}' Input_file

Output will be as follows.
Code:
<event>
1        -2   -1    0    0    0  501  0.00000000000E+00
1         2   -1    0    0  501    0  0.00000000000E+00
1        23    2    1    2    0    0  0.17763568394E-14
1       -15    2    3    3    0    0  0.15027196484E+02
1        15    2    3    3    0    0 -0.15027196484E+02
1       -16    1    4    4    0    0  0.61519221046E+01
1       -13    1    4    4    0    0  0.80239066744E+01
1        14    1    4    4    0    0  0.85136770460E+00
1        16    1    5    5    0    0 -0.11503308753E+02
1        13    1    5    5    0    0 -0.16847543683E+01
1       -14    1    5    5    0    0 -0.18391333621E+01
</event>
<event>
2         2   -1    0    0  501    0  0.00000000000E+00
2        -2   -1    0    0    0  501  0.00000000000E+00
2       -15    2    1    2    0    0 -0.22812990072E+02
2        15    2    1    2    0    0  0.22812990072E+02
2       -16    1    3    3    0    0 -0.17582975494E+01
2       -13    1    3    3    0    0 -0.27110286835E+01
2        14    1    3    3    0    0 -0.18343663839E+02
2        16    1    4    4    0    0  0.76382745636E+01
2        13    1    4    4    0    0  0.45801258260E+01
2       -14    1    4    4    0    0  0.10594589682E+02
</event>


Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

deleting a row if a certain column is below a certain number

How can you delete a row if a certain column is bigger than a certain number? I have the following input: 20080709 20081222 95750 1 0 0.02 94.88 20080709 20081222 95750 2 0 0.89 94.88 20080709 20081222 9575 1 0 0 94.88 20080709 20081222 9575 2 0 0 94.88 20080709 20081222 9587.5 1 0 0... (1 Reply)
Discussion started by: Pep Puigvert
1 Replies

2. UNIX for Dummies Questions & Answers

deleting a row if a certain column is below a certain number

How can you delete a row if a certain column is bigger than a certain number? I have the following input: 20080709 20081222 95750 1 0 0.02 94.88 20080709 20081222 95750 2 0 0.89 94.88 20080709 20081222 9575 1 0 0 94.88 20080709 20081222 9575 2 0 0 94.88 20080709 20081222 9587.5 1 0 0... (6 Replies)
Discussion started by: Pep Puigvert
6 Replies

3. UNIX for Dummies Questions & Answers

Adding a column with the row number using awk

Is there anyway to use awk to add a first column to my data that automatically goes from 1 to n , where n is the numbers of my rows?:confused: (4 Replies)
Discussion started by: cosmologist
4 Replies

4. Shell Programming and Scripting

Count the number or row with same value in a column

This is the source file, we called it errorlist.out 196 server_a server_unix_2 CD 196 server_b server_win_1 CD 196 server_c server_win_2 CD 196 server_bd server_unix_2 CD 196 server_d server_unix_2 CD 196 server_es server_win_1 CD 196 ... (14 Replies)
Discussion started by: sQew
14 Replies

5. Shell Programming and Scripting

How to print column based on row number

Hi, I want to print column value based on row number say multiple of 8. Input file: line 1 67 34 line 2 45 57 . . . . . . line 8 12 46 . . . . . . line 16 24 90 . . . . . . line 24 49 67 Output 46 90 67 (2 Replies)
Discussion started by: Surabhi_so_mh
2 Replies

6. Shell Programming and Scripting

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

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

8. Shell Programming and Scripting

Reading and appending a row from file1 to file2 using awk or sed

Hi, I wanted to add each row of file2.txt to entire length of file1.txt given the sample data below and save it as new file. Any idea how to efficiently do it. Thank you for any help. input file file1.txt file2.txt 140 30 200006 141 32 140 32 200006 142 33 140 35 200006 142... (5 Replies)
Discussion started by: ida1215
5 Replies

9. Shell Programming and Scripting

awk split columns to row after N number of column

I want to split this with every 5 or 50 depend on how much data the file will have. And remove the comma on the end Source file will have 001,0002,0003,004,005,0006,0007,007A,007B,007C,007E,007F,008A,008C Need Output from every 5 tab and remove the comma from end of each row ... (4 Replies)
Discussion started by: ranjancom2000
4 Replies

10. UNIX for Beginners Questions & Answers

Print a row with the max number in a column

Hello, I have this table: chr1_16857_17742 - chr1 17369 17436 "ENST00000619216.1"; "MIR6859-1"; - 67 chr1_16857_17742 - chr1 14404 29570 "ENST00000488147.1"; "WASH7P"; - 885 chr1_16857_18061 - chr1 ... (5 Replies)
Discussion started by: coppuca
5 Replies
SC(4)							   BSD Kernel Interfaces Manual 						     SC(4)

NAME
sc -- Sun Sun-2 SCSI bus host adaptor driver SYNOPSIS
sun2 sc0 at mbmem0 addr 0x80000 ipl 2 sc1 at mbmem0 addr 0x84000 ipl 2 sun2 and sun4 sc0 at vme0 addr 0x200000 irq 2 vec 0x40 DESCRIPTION
The sc driver provides support for the Sun Microsystems "Sun-2" SCSI Bus Controller chipset found on various VME boards (Sun part #s 501-1045, 501-1138, 501-1149, and 501-1167) and on the "Sun-2 SCSI/Serial" (Sun part # 501-1006) Multibus board. All versions of this driver can be configured with a flags directive in the config(1) file. The values are bits in a bitfield, and are interpreted as follows: 0x0ff Set bit (1<<target) to disable SCSI parity checking 0x100 Set this bit to disable DMA interrupts (poll) 0x200 Set this bit to disable DMA entirely (use PIO) For example: "flags 0x1ff" would disable DMA interrupts, and disable parity checking for targets 0-7. The "target" is the SCSI ID number of a particular device on a particular SCSI bus. SEE ALSO
cd(4), ch(4), intro(4), scsi(4), sd(4), st(4) AUTHORS
Matt Fredette <fredette@NetBSD.org>, David Jones, Gordon Ross <gwr@NetBSD.org>, Adam Glass <glass@NetBSD.org>, Jason R. Thorpe <thorpej@NetBSD.org>. BUGS
This SCSI chipset is rumored to have bugs in its handling of SCSI parity, therefore it is recommended that you disable parity on all SCSI devices connected to this controller, and configure it with a 0x0ff value for its flags directive in the config(1) file. This chipset has no support for raising the ATN signal, so there is no way to ever schedule a MSG_OUT phase on the bus. Currently, the driver will ultimately reset the bus if this phase is ever requested by the upper layer SCSI driver. This chipset has no support for SCSI disconnect/reselect. This means that slow devices, such as tape drives, can hog, or "lock up" the SCSI bus. This driver has not been tested in combination with non-SCSI devices behind Emulex or Adaptec bridges, which are common in Sun 2s and in Sun Shoebox-type configurations. These devices pre-date the SCSI-I spec, and might not behave the way the chipset code currently expects. BSD
June 28, 2001 BSD
All times are GMT -4. The time now is 05:18 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy