Count mismatch in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count mismatch in UNIX
# 1  
Old 05-29-2013
Count mismatch in UNIX

Hi,

I have a requirement like below.

client is sending the .txt filles.In that file we have 10 records but when I execute the below command it is showing 9 records.

Code:
klena20> wc -l sample_file.txt|awk '{print $1}'

It is showing the output as 9

But in a file records are 10. I found that in 10th record there is no hit to enter the line.might be this is the issue. To overcome this issue what we can do. Could you please suggest me. client is sending the files like this way only.

Thanks in advance
kirankumar
# 2  
Old 05-29-2013
If there is no newline after the last record, then it will not be counted by wc -l
So it would be best to add an extra newline to the file (a proper Unix text file should have that).

Otherwise you may have better luck with
Code:
awk 'END{print NR}' file

Which would probably work, but you could perhaps run into an implementation of awk where this would not work.

Last edited by Scrutinizer; 05-29-2013 at 02:43 PM..
# 3  
Old 05-29-2013
So, how we can read the no. of records in a file without wc -l. Could you please help me out.

thanks
kirankumar
# 4  
Old 05-29-2013
Another approach would be grep -c . sample_file.txt
# 5  
Old 05-29-2013
Quote:
Originally Posted by verdepollo
Another approach would be grep -c . sample_file.txt
Bad one if blank lines are permitted in the input file.
# 6  
Old 05-29-2013
How about switching the position of awk and wc -l

awk '{print}' sample_file.txt | wc -l

??
# 7  
Old 05-29-2013
Why use awk at all?
Code:
wc -l < sample_file.txt

Did you try Scrutinizer's proposal?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find Syllable count mismatch

Hello, I have written a syllable splitter for Pseudo English and Indic. I have a large database with the following structure Syllables in Pseudo English delimited by |=Syllables in Devanagari delimited by | The tool produces syllables in both scripts. An example is given below: ... (2 Replies)
Discussion started by: gimley
2 Replies

2. Shell Programming and Scripting

awk to output match and mismatch with count using specific fields

In the below awk I am trying output to one file those lines that match between $2,$3,$4 of file1 and file2 with the count in (). I am also trying to output those lines that are missing between $2,$3,$4 of file1 and file2 with the count of in () each. Both input files are tab-delimited, but the... (7 Replies)
Discussion started by: cmccabe
7 Replies

3. Shell Programming and Scripting

Mismatch in summing a column in UNIX

Hello, I am facing issue in summing up a column in unix.I am displaying a column sum up to 4 decimal places and below is the code snippet sed '1d' abc.csv | cut -d',' -f7 | awk '{s+=$1}END{ printf("%.4f\n",s)}' -170552450514.8603 example of data values in the column(not... (3 Replies)
Discussion started by: karthik adiga
3 Replies

4. Shell Programming and Scripting

Need help in comparing two files in UNIX with a mismatch

Hi Everyone, I am comparing results of two environments using unix files. I am writing two different csv file using spool and merging both the files using paste command paste -d, file1.csv file2.csv > prod_uat_result.csv and then finding the difference and attaching the same in a mail... (8 Replies)
Discussion started by: karthik adiga
8 Replies

5. Shell Programming and Scripting

Character count in UNIX!

Hi, I am Beginner in writing shell scripting. I have tried to get the character count using wc command. But it is not giving the correct result. Could any one please tell me the reason? $ cat k.ksh Shell scripting The character count should be 15 but it is displaying as 16 when i use... (8 Replies)
Discussion started by: nikesh29
8 Replies

6. UNIX for Dummies Questions & Answers

Files count mismatch when used with Tar with find

Hi I have used the below steps and found some discrepancies step 1 : find ./ -type f -mtime +7 -name "*.00*" | wc -l = 13519 ( total files ) ( the size of this files is appx : 10GB ) step 2: find ./ -type f -mtime +7 -name "*.00*" | xargs tar zcvf Archieve_7.tar.gz step... (7 Replies)
Discussion started by: rakeshkumar
7 Replies

7. HP-UX

about HP-UX error exa_parm mismatch?

Hi, anyone can give me the answer about Fatal: HP-UX error exa_parm mismatch? We are running HP-UX ver. 9.0.1 also running some OCP software along with Licensed dongle. Every three to four hour (some time it will last up to 24 hour) the OCP software shutdown unexpectedly (0 Replies)
Discussion started by: monukwt
0 Replies

8. Shell Programming and Scripting

To find String mismatch

Hi, I have a doubt when searching files for the existence of a particular key. I have a property file has data with key and value pair like below and i call it as property file.ini here are the contents in File: popertyfile.ini location.property=2 agent.method=begin newkey=23 ... (2 Replies)
Discussion started by: raghu.amilineni
2 Replies

9. HP-UX

how to see the threads count of a process in hp unix?

hi,all: how to see the threads count of a process in hp unix? thanks (2 Replies)
Discussion started by: bugbugbug
2 Replies
Login or Register to Ask a Question