word count showing wrong number of lines


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers word count showing wrong number of lines
# 1  
Old 01-05-2004
word count showing wrong number of lines

Hi ,
I am using SUN OS Version 5.6.
I have a file that contains records of length 270. when I do 'set nu' in vi editor, I get the count as 86. whereas when I do "wc -l" on the command prompt, it shows the count as only 85. this is very strange. why would the 'wc' show 1 record less. The job that processed the file shows in the log that it loaded 86 records.
I checked the last record in that file and it is exactly the same as the other records and of same record length.

can anyone answer my question pls.
# 2  
Old 01-05-2004
My guess is that the last record in your file does not contain a newline character after it.

For example, if you type echo -n "hi" > someFile and then try wc -l someFile it'll show the file as having 0 lines, since the -n option doesn't put a newline character at the end of the line.

And when you vi your file, you should see something like "yourFile" [Incomplete last line] ... at the bottom of the screen. You could fix this by running a command like echo >> yourFile.
# 3  
Old 01-05-2004
I would try this to get rid of any blank lines.


grep -v ^$ file.in > file.out



Then use file.out for your testing.
# 4  
Old 01-06-2004
Use a set list within vi to see special characters. You could also do an od -c file to take a look at the contents to see if you are missing the last terminating newline.

Cheers,

Keith
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

perl count lines with certain word int

Hi Guys I have a text file that contains the message like this /var/log/messages.all-20120401: Mar 26 12:12:23 brent kernel: NVRM: Xid (0003:00): 43, 0005 00009097 00000000 00000000 00001b0c 1000f010 /var/log/messages.all-20120401: Mar 27 20:42:40 brent kernel: NVRM: Xid (0003:00): 43,... (4 Replies)
Discussion started by: ab52
4 Replies

2. UNIX for Dummies Questions & Answers

how to count number of times each word exist in a file

I'm trying to count the number of times each word in the file exist for example if the file has: today I have a lot to write, but I will not go for it. The main thing is that today I am looking for a way to get each word in this file with a word count after it specifying that this word has... (4 Replies)
Discussion started by: shnkool
4 Replies

3. Shell Programming and Scripting

Need script to count specific word and iterate over number of files.

Hi Experts, I want to know the count of specific word in a file. I have almost 600+ files. So I want to loop thru each file and get the count of the specific word. Please help me on achieving this... Many thanks (2 Replies)
Discussion started by: elamurugu
2 Replies

4. Shell Programming and Scripting

count the number of lines that start with the number

I have a file with contents similar to this. abcd 1234 4567 7666 jdjdjd 89289 9382 92 jksdj 9823 298 I want to write a shell script which count the number of lines that start with the number (disregard the lines starting with alphabets) (1 Reply)
Discussion started by: grajp002
1 Replies

5. Shell Programming and Scripting

Word count of lines ending with certain word

Hi all, I am trying to write a command that can help me count the number of lines in the /etc/passwd file ending in bash. I have read through other threads but am yet to find one indicating how to locate a specifc word at the end of a line. I know i will need to use the wc command but when i... (8 Replies)
Discussion started by: warlock129
8 Replies

6. Shell Programming and Scripting

Count the number of occurrences of the word

I am a newbie in UNIX shell script and seeking help on this UNIX function. Please give me a hand. Thanks. I have a large file. Named as 'MyFile'. It was tab-delmited. I am told to write a shell function that counts the number of occurrences of the ord “mysring” in the file 'MyFile'. (1 Reply)
Discussion started by: duke0001
1 Replies

7. UNIX for Dummies Questions & Answers

Count number of occurences of a word

I want to count the number of occurences of say "200" in a file but that file also contains various stuff including dtaes like 2007 or smtg like 200.1 so count i am getting by doing grep -c "word" file is wrong Please help!!!!! (8 Replies)
Discussion started by: shikhakaul
8 Replies

8. Shell Programming and Scripting

scripting - write a script that will count the number of times a particular word

hello everyone, I'm trying to learn some scripts but i cant get my head around two of them. 1. how can i write a script that will count the number of times a particular word is used in file? 2. how can i make a script that will take me to a web page from unix? if anyone could help it... (3 Replies)
Discussion started by: BigTool4u2
3 Replies

9. Shell Programming and Scripting

Count number of digits in a word

Hi all Can anybody suggest me, how to get the count of digits in a word I tried WORD=abcd1234 echo $WORD | grep -oE ] | wc -l 4 It works in bash command line, but not in scripts :mad: (12 Replies)
Discussion started by: ./hari.sh
12 Replies

10. Shell Programming and Scripting

Count the number of occurence of perticular word from file

I want to count the number of occurence of perticular word from one text file. Please tell me "less" command is work in ksh or not. If it is not working then instead of that which command will work. :confused: (40 Replies)
Discussion started by: rinku
40 Replies
Login or Register to Ask a Question