Sponsored Content
Top Forums Shell Programming and Scripting how to add the number of row and count number of rows Post 302437363 by durden_tyler on Wednesday 14th of July 2010 08:47:28 PM
Old 07-14-2010
Here's one way to do it with Perl -

Code:
$
$
$ cat f3
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
21 4567 C
23 4567 A
23 4567 A
23 4567 A
23 4567 A
23 4567 C
23 4567 C
23 4567 C
$
$
$
$ perl -ne 'chomp; s/\s*$//; s/\s+/:/g; $fmt="%s %s %s %d %d\n";
          if (! defined $x{$_} && $.>1) {
            while (($k,$n) = each(%x)) {
              foreach $i (1..$n) {printf($fmt, split(/:/,$k), $i, $n)}
            }
            %x = (); $x{$_}++;
          } else {$x{$_}++}
          END {
            while (($k,$n) = each(%x)) {
              foreach $i (1..$n) {printf($fmt, split(/:/,$k), $i, $n)}
            }
          }' f3
21 2341 A 1 3
21 2341 A 2 3
21 2341 A 3 3
21 2341 C 1 4
21 2341 C 2 4
21 2341 C 3 4
21 2341 C 4 4
21 4567 A 1 2
21 4567 A 2 2
21 4567 C 1 2
21 4567 C 2 2
23 4567 A 1 4
23 4567 A 2 4
23 4567 A 3 4
23 4567 A 4 4
23 4567 C 1 3
23 4567 C 2 3
23 4567 C 3 3
$
$

tyler_durden
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

row count but only number part

hi i am pretty new to unix .i am ETL guy I need a unix script to take row count of a file and write it to another file the problem with wc-l is it include filename also wc -l abc.dat will give me like 1000 abc.dat i just want 1000 to be written can u just take 2 min to write a simple... (1 Reply)
Discussion started by: er_zeeshan05
1 Replies

2. Shell Programming and Scripting

count number of nonempty columns in row

Hi, Suppose i have a inputfile in csv format. How to use awk to count 'the number of nonempty columns in each row' minus one, and add the value as a new column in the end For cosmetic reason, it's even better to include a descriptive label for the last column in the first row. for... (2 Replies)
Discussion started by: grossgermany
2 Replies

3. UNIX for Dummies Questions & Answers

how to count number of rows and sum of column using awk

Hi All, I have the following input which i want to process using AWK. Rows,NC,amount 1,1202,0.192387 2,1201,0.111111 3,1201,0.123456 i want the following output count of rows = 3 ,sum of amount = 0.426954 Many thanks (2 Replies)
Discussion started by: pistachio
2 Replies

4. UNIX for Dummies Questions & Answers

count number of rows based on other column values

Could anybody help with this? I have input below ..... david,39 david,39 emelie,40 clarissa,22 bob,42 bob,42 tim,32 bob,39 david,38 emelie,47 what i want to do is count how many names there are with different ages, so output would be like this .... david,2 emelie,2 clarissa,1... (3 Replies)
Discussion started by: itsme999
3 Replies

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

6. Shell Programming and Scripting

Extract and count number of Duplicate rows

Hi All, I need to extract duplicate rows from a file and write these bad records into another file. And need to have a count of these bad records. i have a command awk ' {s++} END { for(i in s) { if(s>1) { print i } } }' ${TMP_DUPE_RECS}>>${TMP_BAD_DATA_DUPE_RECS}... (5 Replies)
Discussion started by: Arun Mishra
5 Replies

7. Shell Programming and Scripting

Awk/sed script for transposing any number of rows with header row

Greetings! I have been trying to find out a way to take a CSV file with a large number of rows, and a very large number of columns (in the thousands) and convert the rows to a single column of data, where the first row is a header representing the attribute name and the subsequent series of... (3 Replies)
Discussion started by: tntelle
3 Replies

8. UNIX for Dummies Questions & Answers

Script to count number of rows

Hi, I need a solaris shell script to read multiple files and count number of unique name rows(strings) from those files. The input and output should be like this Input: file 1 abc cde abc ... (9 Replies)
Discussion started by: ssk250
9 Replies

9. UNIX for Dummies Questions & Answers

I want count of number of records to be printed on each row.

we want the count of number of records to be printed on each row. For Ex: if there are 5 records on one unique id , the count "5'' should be printed on each record in other column. Please help for this. I am using unix & Cygwin. Below are sample records: KCZ0650473... (2 Replies)
Discussion started by: ElijaRajesh
2 Replies

10. Shell Programming and Scripting

Reseting row count every given number of rows

I have a file with 48 rows. I am counting 6 rows and adding 6 to that number and repeating the operation, and then output the value in column 1. For the second column, I would like to get sort of a binary output (1s and 2s) every 3rd row. This is what I have: awk '{print ++src +... (1 Reply)
Discussion started by: Xterra
1 Replies
CHUCK(1)						      General Commands Manual							  CHUCK(1)

NAME
chuck -- audio programming language for real-time synthesis, composition, and performance SYNOPSIS
chuck [--halt] [--loop] [--audio] [--silent] [--dump] [--nodump] [--about] [--srateN] [--bufsizeN] [--bufnumN] [--dacN] [--adcN] [--remotehostname] [--portN] [--verboseN] [--probe] [--blocking] [--callback] [--add] [--remove] [--replace] [--status] [--time] [--kill] [--version] [+] [-] [=] [^] [file1] [file2] [file2] DESCRIPTION
This manual page documents briefly the chuck commands. chuck is a new audio programming language for real-time synthesis, composition, and performance, which runs on commodity operating systems. chuck presents a new time-based concurrent programming model, which supports multiple, simultaneous, dynamic control rates, and the ability to add, remove, and modify code, on-the-fly, while the program is running, without stopping or restarting. Use chuck for jack audio interfaces, chuck.alsa to access alsa devices, and chuck.oss to access oss devices. OPTIONS
A summary of options is included below. --add file.ck Add a file to a running chuck server. --remove shrednumber Remove a shred to a running chuck server. --replace shrednumber file.ck Replace an existing shred with another file. --status Print chuck server status information. + - = ^ Shortcuts for add, remove, replace and status. --time Get the current time. --kill Kill the chuck server. --halt Start in halt mode (default). --loop Start chuck in loop mode (daemon mode). --audio Start server with audio (default). --silent Start server in silent mode. --dump Dump compilation result (verbose mode). --nodump Do not dump compilation result. --srateN Set sampling rate (default to 48000 for jack, auto detected otherwise). --bufsizeN Set buffer size. --bufnumN Set number of buffer. --dacN Set output audio device. --adcN Set input audio device. --remotehostname Connect to remote hostname. --portN Connect/Listen on port number N. --verboseN Set verbosity level to N. --probe List available audio devices. --blocking Use blocking mode audio access. --callback Use callback mode audio access. --about --help Show summary of options. --version Show version of program. SEE ALSO
/usr/share/doc/chuck/ChucK_manual.pdf EXAMPLES
$ cd /usr/share/doc/chuck/examples $ chuck otf_01.ck & $ chuck --add otf_02.ck & $ chuck + otf_0[4567].ck $ chuck - 0 $ chuck --kill AUTHOR
This manual page was written by Paul Brossier <piem@altern.org>. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU General Public License, Version 2 any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. CHUCK(1)
All times are GMT -4. The time now is 03:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy