AWK print number of records, divide this number


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK print number of records, divide this number
# 8  
Old 06-30-2012
Code:
awk 'FNR<NR && FNR==1{lcnt=NR-1} END{print lcnt/FNR}' file1 file2

---------- Post updated at 09:51 AM ---------- Previous update was at 09:25 AM ----------

Actually, I hadn't seen Franklin52's code before posting...Smilie
Sorry for that...
Now that I've seen it, it differs slightly in that I am executing the action only once when FNR has been reset to 1 due to input file change.
# 9  
Old 06-30-2012
Hi.
Quote:
Originally Posted by elixir_sinari
Code:
awk 'FNR<NR && FNR==1{lcnt=NR-1} END{print lcnt/FNR}' file1 file2

---------- Post updated at 09:51 AM ---------- Previous update was at 09:25 AM ----------

Actually, I hadn't seen Franklin52's code before posting...Smilie
Sorry for that...
Now that I've seen it, it differs slightly in that I am executing the action only once when FNR has been reset to 1 due to input file change.
Yes, I agree, and on long files that would save some time.

Thanks for looking at them both ... cheers, drl
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

2. UNIX for Dummies Questions & Answers

Make all records with the same number of fields (awk)

Hi, input: AA|BB|CC DD|EE FF what I am trying to get: AA|BB|CC DD|EE| FF|| I tried to create first an UDF for printing repeats, but I think I have an issue with my END section or my array: function repeat(str, n, rep, i) { for(i=1 ;i<n;i++) rep=rep str return rep } ... (6 Replies)
Discussion started by: beca123456
6 Replies

3. Shell Programming and Scripting

Is it possible to Divide a negative number in bash script

I am using a small script to divide some numbers in a given file and display the output in another file. I am getting the following error basename: invalid option -- '5' Try `basename --help' for more information. (standard_in) 1: syntax error The script is : #!/bin/bash for i in `cat... (4 Replies)
Discussion started by: kmnr877
4 Replies

4. Shell Programming and Scripting

Perl : print the sequence number without missing number

Dear Perl users, I need your help to solve my problem below. I want to print the sequence number without missing number within the range. E.g. my sequence number : 1 2 3 4 5 6 7 8 11 12 13 14 my desired output: 1 -8 , 11-14 my code below but still problem with the result: 1 - 14 1 -... (2 Replies)
Discussion started by: mandai
2 Replies

5. Shell Programming and Scripting

AWK: Cannot read Number of records greater than 1(NR>1)

Hi all, I have a tab-delimited text file of size 10Mb. I am trying to count the number of lines using, grep -c . sample.txtor wc -l < sample.txt or awk 'END {print NR}' sample.txtAll these commands shows the count as 1, which means they are reading only the first header line of the file.... (3 Replies)
Discussion started by: mehar
3 Replies

6. Shell Programming and Scripting

Print records which do not have expected number of fields in a comma delimited file

Hi, I have a comma (,) delimited file, in which few fields are enclosed with in double quotes " ". I have to print the records in the file which donot have expected number of field with the line number. File1 ==== name,desgnation,doj,project #header#... (7 Replies)
Discussion started by: machomaddy
7 Replies

7. Shell Programming and Scripting

Add and divide each numbers with the added number

Hi All, I am stuck with this problem. I have some 100000 (.dat) 1.dat, 2.dat,3.dat etc until 100000.dat files which look like this: 1.dat 1 2 3 4 0.99 4.54 All my files 1.dat until 100000.dat look the same but with different numbers. I have to first add all the numbers in each... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

8. Shell Programming and Scripting

Please help. How to print number with 'awk'?

Dear all, I have to transform a bunch of files into a new format. how to do it with bash script, especially with 'awk' command. the original data O,0,0.2839896442,-1.1628392411,-1.5976515479 Cr,0,-0.0502858628,-0.1725974837,-0.380627632 C,0,2.4506658279,-0.476964918,0.2299298249 ... (3 Replies)
Discussion started by: liuzhencc
3 Replies

9. Shell Programming and Scripting

awk - Number of records

Hi, Is it possible to find the total number of records processed by awk at begining. NR gives the value at the end. Is there any variable available to find the value at the begining? Thanks ---------- Suman (1 Reply)
Discussion started by: suman_jakkula
1 Replies

10. Shell Programming and Scripting

How to print number of lines with awk ?

Can some body tell me how to print number of line from a particular file, with sed. ? Input file format AAAA BBBB CCCC SDFFF DDDD DDDD Command to print line 2 and 3 ? BBBB CCCC And also please tell me how to assign column sum to variable. I user the following command it... (1 Reply)
Discussion started by: maheshsri
1 Replies
Login or Register to Ask a Question