Sponsored Content
Top Forums Shell Programming and Scripting Analyzing last 2 fields of 1 row and 3rd field of next row Post 303034474 by RudiC on Friday 26th of April 2019 04:19:19 PM
Old 04-26-2019
For exactly your above laid out problem, try
Code:
awk 'NR > 1 {print LEADIN, (sum+$3)/3} {LEADIN = $1 OFS $2; sum = $13 + $14} ' file
01001 271895 59.5933
01001 271896 60.9133
01001 271897 62.4867

The output format can be modified by setting the OFMT variable.
For a two field summation, a for loop is not necessary, and you don't need a count if you're always adding three elements. If, on the other hand, you want a more generic approach, combine your attempt with this one.
These 2 Users Gave Thanks to RudiC For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Changing the column for a row in a text file and adding another row

Hi, I want to write a shell script which increments a particular column in a row from a text file and then adds another row below the current row with the incremented value . For Eg . if the input file has a row : abc xyz lmn 89 lm nk o p I would like the script to create something like... (9 Replies)
Discussion started by: aYankeeFan
9 Replies

2. Shell Programming and Scripting

How to insert data befor some field in a row of data depending up on values in row

Hi I need to do some thing like "find and insert before that " in a file which contains many records. This will be clear with the following example. The original data record should be some thing like this 60119827 RTMS_LOCATION_CDR INSTANT_POSITION_QUERY 1236574686123083rtmssrv7 ... (8 Replies)
Discussion started by: aemunathan
8 Replies

3. Shell Programming and Scripting

how to spilit a row into fields and store the field content to the array

consider this is a line A#B#C#D#E#F#G#H note the delimeter is # i want to cut or spilt in to fields using the delimeter # and to store in an array. like this array=A array=B array=C array=D array=E and the array content should be displayed. echo "${array}" echo "${array}"... (5 Replies)
Discussion started by: barani75
5 Replies

4. Shell Programming and Scripting

To count distinct fields in a row

I have . dat file which contains data in a specific format: 0 3 892 921 342 1 3 921 342 543 2 4 817 562 718 765 3 3 819 562 717 761 i need to compare each field in a row with another field of the same column but different row and cont the... (8 Replies)
Discussion started by: Abhik
8 Replies

5. UNIX for Dummies Questions & Answers

Shell Script: Traverse Database Table Row by Row

Hello Everyone, My issue is that I want to traverse a database table row by row and do some action on the value retrieved in each row. I have gone through a lot of shell script questions/posts. I could find row by row traversal of a file but not a database table. Please help. Thanks &... (5 Replies)
Discussion started by: ahsan.asghar
5 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. Shell Programming and Scripting

Add Row from First Row (Split Row)

HI Guys, I have Below Input :- RepigA_hteis522 ReptCfiEtrBsCll_aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 RepigA ReptCfiEtrBsCll hteis522 aofe MSL04_MSL2_A25_1A 0 9 MSL04_MSL2_A25_1B 0 9 MSL04_MSL2_A25_1C 0 9 Split Data in two first row... (2 Replies)
Discussion started by: pareshkp
2 Replies

8. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

My original files are like this below and I distinguish them from the AP_ID (file1 has 572 and file2 has 544). Also, the header on file1 has “G_” pre-pended. NOTE: these are only snippets of very large files and much of the data is not present here. Original File 1: ... (36 Replies)
Discussion started by: aachave1
36 Replies

9. Shell Programming and Scripting

Splitting single row into multiple rows based on for every 10 digits of last field of the row

Hi ALL, We have requirement in a file, i have multiple rows. Example below: Input file rows 01,1,102319,0,0,70,26,U,1,331,000000113200000011920000001212 01,1,102319,0,1,80,20,U,1,241,00000059420000006021 I need my output file should be as mentioned below. Last field should split for... (4 Replies)
Discussion started by: kotra
4 Replies

10. UNIX for Beginners Questions & Answers

Keep only the closet match of timestamped row (include headers) from file1 to precede file2 row/s

This is a question that is related to one I had last August when I was trying to sort/merge two files by millsecond time column (in this case column 6). The script (below) that helped me last august by RudiC solved the puzzle of sorting/merging two files by time, except it gets lost when the... (0 Replies)
Discussion started by: aachave1
0 Replies
MSSQL_FETCH_ROW(3)														MSSQL_FETCH_ROW(3)

mssql_fetch_row - Get row as enumerated array

SYNOPSIS
array mssql_fetch_row (resource $result) DESCRIPTION
mssql_fetch_row(3) fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0. Subsequent call to mssql_fetch_row(3) would return the next row in the result set, or FALSE if there are no more rows. PARAMETERS
o $result - The result resource that is being evaluated. This result comes from a call to mssql_query(3). RETURN VALUES
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows. EXAMPLES
Example #1 mssql_fetch_row(3) example <?php // Connect to MSSQL and select the database $link = mssql_connect('MANGOSQLEXPRESS', 'sa', 'phpfi'); mssql_select_db('php', $link); // Query to execute $query = mssql_query('SELECT [id], [quote] FROM [quotes] WHERE [id] = '42'', $link); // Did the query fail? if (!$query) { die('MSSQL error: ' . mssql_get_last_message()); } // Fetch the row $row = mssql_fetch_row($query); // Print the 'quote' echo 'Quote #' . $row[0] . ': "' . $row[1] . '"'; ?> The above example will output something similar to: Quote #42: "The answer to everything..." NOTES
Note This function sets NULL fields to the PHP NULL value. SEE ALSO
mssql_fetch_array(3), mssql_fetch_object(3), mssql_data_seek(3), mssql_result(3). PHP Documentation Group MSSQL_FETCH_ROW(3)
All times are GMT -4. The time now is 12:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy