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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting AWK: Cannot read Number of records greater than 1(NR>1)
# 1  
Old 02-12-2012
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,

Code:
grep -c . sample.txt

or
Code:
wc -l < sample.txt

or
Code:
awk 'END {print NR}'  sample.txt

All these commands shows the count as 1, which means they are reading only the first header line of the file. None of the commands are giving the correct count of lines.

Could anyone help to get the count of all lines in the file using awk. A sample file is attached for reference.

Last edited by radoulov; 02-12-2012 at 06:18 PM.. Reason: Code tags.
# 2  
Old 02-12-2012
Run
Code:
perl -pe 's/\r/\n/g' sample.txt > sample2.txt

Then
Code:
wc -l sample2.txt

This User Gave Thanks to bartus11 For This Post:
# 3  
Old 02-12-2012
Quote:
Originally Posted by mehar
All these commands shows the count as 1, which means they are reading only the first header line of the file. None of the commands are giving the correct count of lines.
Actually, it means, there's no new lines as they understand it.

Would this work?
Code:
awk 'BEGIN{ RS="\r" } END{print NR}' sample.txt

These 2 Users Gave Thanks to Aia For This Post:
# 4  
Old 02-13-2012
Quote:
Originally Posted by Aia
Actually, it means, there's no new lines as they understand it.

Would this work?
Code:
awk 'BEGIN{ RS="\r" } END{print NR}' sample.txt

Thanks!! it worked.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

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

2. UNIX for Dummies Questions & Answers

Greater than specific number

please let me know how to construct if then else by comparing two numbers if it is greater than 10000. I need to do some specific task executed. can you help me out in shell scripting plz. (6 Replies)
Discussion started by: ramkumar15
6 Replies

3. Shell Programming and Scripting

Grep lines for number greater than given number

Hello, I am newbie to bash scripting. Could someone help me with the following. I have log file with output as shown below **************************LOG************************* 11/20/2013 9:11:23.64 Pinging xx.xx.xx.xx with 32 bytes of data: 11/20/2013 9:11:23.64 Reply from xx.xx.xx.xx:... (4 Replies)
Discussion started by: meena_2013
4 Replies

4. Shell Programming and Scripting

Need to get all the records from a log file greater than timestamp supplied.

I have a log file which has records with hung thread information/error I need to find out hung thread from log file greater than timestamp supplied. 00000026 ThreadMonitor W WSVR0605W: Thread "WebContainer : 1" (00000027) has been active for 701879 milliseconds and may be hung. There is/are... (6 Replies)
Discussion started by: megh
6 Replies

5. Shell Programming and Scripting

Egrep a greater than number

data: hello mr smith 400 you all ok? hello mrs. smith 700 you all ok? hello mr. everyone 150 you all ok? hello mr. you all 199 im lad you are ok using egrep, how can i grep out only lines that have a number greater than 250? cat data | egrep ..... can't use awk here. i was... (7 Replies)
Discussion started by: SkySmart
7 Replies

6. Shell Programming and Scripting

Compare two files with different number of records and output only the Extra records from file1

Hi Freinds , I have 2 files . File 1 |nag|HYd|1|Che |esw|Gun|2|hyd |pra|bhe|3|hyd |omu|hei|4|bnsj |uer|oeri|5|uery File 2 |nag|HYd|1|Che |esw|Gun|2|hyd |uer|oi|3|uery output : (9 Replies)
Discussion started by: i150371485
9 Replies

7. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

8. UNIX for Dummies Questions & Answers

check if a decimal number is greater than zero

Hello, In my code I am checking to see if a variable that contains a decimal number is greater than 0 in the following manner: if do something fi However I am getting the error message (if $i for the current iteration holds 9.6352) command 9.6352 is not found How can I rectify... (5 Replies)
Discussion started by: Gussifinknottle
5 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

[awk]: Row begins by random number and field 10 is greater than 10.00%

Hello! I wish to extract the pid where CPU is above 10% last pid: 22621; load averages: 4.71, 5.04, 5.13 15:08:34 221 processes: 212 sleeping, 2 running, 1 stopped, 6 on cpu CPU states: %... (3 Replies)
Discussion started by: Lomic
3 Replies
Login or Register to Ask a Question

Featured Tech Videos