Count mismatch in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count mismatch in UNIX
# 8  
Old 05-30-2013
If you know that you have a file that is supposed to be a text file but is missing the newline that should be at the end of the file, the easy way to fix it is:
Code:
echo >> file

Note that Scrutinizer's suggestion and juzz4fun's suggestion will work with some versions of awk, but not all. The standards don't define the behavior of awk when the last line is not terminated by a <newline> character. I know that some existing versions of awk would produce the same results as wc by itself and others would produce the number you wanted. Others could do anything they want to do (such as terminate with an error message and write nothing to standard output) and still conform to the standards!

If some files are correctly formatted text files (with the trailing <newline>) and others are missing the trailing <newline>, but you know that there are always supposed to be 10 lines in the file, you could convert the incorrectly formatted files to correctly formatted text files using:
Code:
[ $(wc -l sample_file.txt) -eq 10 ] || echo >> sample_file.txt

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