Sponsored Content
Full Discussion: Number Grouped Rows in File
Top Forums UNIX for Dummies Questions & Answers Number Grouped Rows in File Post 302172328 by radoulov on Monday 3rd of March 2008 11:27:30 AM
Old 03-03-2008
Code:
awk '!x[$3,$4]++{c++}$0=c FS$0' c=99 OFS=":" FS=":"

or

Code:
awk '$0=(!x[$3,$4]++?++c:c)FS$0' c=99 OFS=":" FS=":"


Use nawk or /usr/xpg4/bin/awk on Solaris.

Last edited by radoulov; 03-03-2008 at 12:40 PM.. Reason: added another version
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Splitting file based on number of rows

Hi, I'm, new to shell scripting, I have a requirement where I have to split an incoming file into separate files each containing a maximum of 3 million rows. For e.g: if my incoming file say In.txt has 8 mn rows then I need to create 3 files, in which two will 3 mn rows and one will contain 2... (2 Replies)
Discussion started by: wahi80
2 Replies

2. Shell Programming and Scripting

how to add the number of row and count number of rows

Hi experts a have a very large file and I need to add two columns: the first one numbering the incidence of records and the another with the total count The input file: 21 2341 A 21 2341 A 21 2341 A 21 2341 C 21 2341 C 21 2341 C 21 2341 C 21 4567 A 21 4567 A 21 4567 C ... (6 Replies)
Discussion started by: juelillo
6 Replies

3. Shell Programming and Scripting

How to add the number of events grouped by field

Help i need to add to the end of the line the number of event grouped by id, my input file: IN FILE: ID DATE 10123 01-04-2008 10123 06-05-2008 10123 01-09-2009 10123 11-12-2009 10345 01-22-2008 10345 06-15-2008 10127 02-22-2010 OUT FILE: ID DATE EVENT_NUMBER 10123 01-04-2008 1... (3 Replies)
Discussion started by: juelillo
3 Replies

4. Shell Programming and Scripting

awk number rows from 1 to 3 in file

I have a file with the following format, i need to change de field9 each 3 rows to renumber field9 with gpo1, gpo2, gpo3. I need to use awk Original file field1 field2 field3 field4 field5 field6 field7 field8 gpo3 field1 field2 field3 field4 field5 ... (3 Replies)
Discussion started by: robonet
3 Replies

5. UNIX Desktop Questions & Answers

Need to ftp some files, and check the number of rows in the transferd file

1)I need to write a script which ftps 3 files to a unix box, 2)once the files are ftped i need to check the number of rows in each file and compare it with the data (no of rows) coming in a manifest file, if the number of rows in each file matches the data coming in manifest file, then i need to... (3 Replies)
Discussion started by: imran_affu
3 Replies

6. UNIX for Advanced & Expert Users

merge two tab delimited file with exact same number of rows in unix/linux

Hi I have two tab delimited file with different number of columns but same number of rows. I need to combine these two files in such a way that row 1 in file 2 comes adjacent to row 1 in file 1. For example: The content of file1: field1 field2 field3 a1 a2 a3 b1 b2 b3... (2 Replies)
Discussion started by: mary271
2 Replies

7. UNIX for Dummies Questions & Answers

How to separate a single column file into files of the same size (i.e. number of rows)?

I have a text file with 1,000,000 rows (It is a single column text file of numbers). I would like to separate the text file into 100 files of equal size (i.e. number of rows). The first file will contain the first 10,000 rows, the second row will contain the second 10,000 rows (rows 10,001-20,000)... (2 Replies)
Discussion started by: evelibertine
2 Replies

8. UNIX for Dummies Questions & Answers

Write the total number of rows in multiple files into another file

Hello Friends, I know you all are busy and inteligent too... I am stuck with one small issue if you can help me then it will be really great. My problem is I am having some files i.e. Input.txt1 Input.txt2 Input.txt3 Now my task is I need to check the total number of rows in... (4 Replies)
Discussion started by: malaya kumar
4 Replies

9. Shell Programming and Scripting

extracting number of rows

if > wc -l data.txt > 100 (meaning there are 100 rows) i want to assgn 100 as n so that if i do >echo n it would give me 100 Thanks (5 Replies)
Discussion started by: johnkim0806
5 Replies

10. Shell Programming and Scripting

Split File based on number of rows

Hi I have a requirement, where i will receive multiple files in a folder (say: /fol1/fol2/). There will be at least 14 to 16 files. The size of the files will different, some may be 80GB or 90GB, some may be less than 5 GB (and the size of the files are very unpredictable). But the names of the... (10 Replies)
Discussion started by: kpk_ds
10 Replies
MYSQL_AFFECTED_ROWS(3)							 1						    MYSQL_AFFECTED_ROWS(3)

mysql_affected_rows - Get number of affected rows in previous MySQL operation

SYNOPSIS
Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: omysqli_affected_rows(3) o PDOStatement::rowCount int mysql_affected_rows ([resource $link_identifier = NULL]) DESCRIPTION
Get the number of affected rows by the last INSERT, UPDATE, REPLACE or DELETE query associated with $link_identifier. o $ link_identifier -The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect(3) is assumed. If no such link is found, it will try to create one as if mysql_connect(3) was called with no arguments. If no connection is found or established, an E_WARNING level error is generated. Returns the number of affected rows on success, and -1 if the last query failed. If the last query was a DELETE query with no WHERE clause, all of the records will have been deleted from the table but this function will return zero with MySQL versions prior to 4.1.2. When using UPDATE, MySQL will not update columns where the new value is the same as the old value. This creates the possibility that mysql_affected_rows(3) may not actually equal the number of rows matched, only the number of rows that were literally affected by the query. The REPLACE statement first deletes the record with the same primary key and then inserts the new record. This function returns the number of deleted records plus the number of inserted records. In the case of "INSERT ... ON DUPLICATE KEY UPDATE" queries, the return value will be 1 if an insert was performed, or 2 for an update of an existing row. Example #1 mysql_affected_rows(3) example <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('mydb'); /* this should return the correct numbers of deleted records */ mysql_query('DELETE FROM mytable WHERE id < 10'); printf("Records deleted: %d ", mysql_affected_rows()); /* with a where clause that is never true, it should return 0 */ mysql_query('DELETE FROM mytable WHERE 0'); printf("Records deleted: %d ", mysql_affected_rows()); ?> The above example will output something similar to: Records deleted: 10 Records deleted: 0 Example #2 mysql_affected_rows(3) example using transactions <?php $link = mysql_connect('localhost', 'mysql_user', 'mysql_password'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('mydb'); /* Update records */ mysql_query("UPDATE mytable SET used=1 WHERE id < 10"); printf ("Updated records: %d ", mysql_affected_rows()); mysql_query("COMMIT"); ?> The above example will output something similar to: Updated Records: 10 Note Transactions If you are using transactions, you need to call mysql_affected_rows(3) after your INSERT, UPDATE, or DELETE query, not after the COMMIT. Note SELECT Statements To retrieve the number of rows returned by a SELECT, it is possible to use mysql_num_rows(3). Note Cascaded Foreign Keys mysql_affected_rows(3) does not count rows affected implicitly through the use of ON DELETE CASCADE and/or ON UPDATE CASCADE in for- eign key constraints. mysql_num_rows(3), mysql_info(3). PHP Documentation Group MYSQL_AFFECTED_ROWS(3)
All times are GMT -4. The time now is 02:11 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy