The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Count number of occurences of a word shikhakaul UNIX for Dummies Questions & Answers 7 11-30-2007 04:22 PM
Count the number of occurence of perticular word from file rinku Shell Programming and Scripting 40 08-10-2007 04:33 PM
How to count lines - ignoring blank lines and commented lines kthatch UNIX for Dummies Questions & Answers 6 05-24-2007 10:21 PM
Count number of lines in Binary file vanand420 Shell Programming and Scripting 3 09-04-2005 10:07 PM
counting lines and showing the output jjoves UNIX for Dummies Questions & Answers 13 08-03-2004 06:45 AM

Closed Thread
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-05-2004
Registered User
 

Join Date: Sep 2003
Posts: 10
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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.
Forum Sponsor
  #2 (permalink)  
Old 01-05-2004
oombera's Avatar
Have a day :|
 

Join Date: Aug 2002
Location: Cleveland, OH
Posts: 804
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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 (permalink)  
Old 01-05-2004
Kelam_Magnus's Avatar
Unix does a body good.
 

Join Date: Aug 2001
Location: DFW McKinney, TX,
Posts: 1,069
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
I would try this to get rid of any blank lines.


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



Then use file.out for your testing.
__________________
My brain is your brain
  #4 (permalink)  
Old 01-06-2004
kduffin's Avatar
UN1X
 

Join Date: Nov 2003
Location: Virginia
Posts: 441
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit! Stumble this Post!Spurl this Post!
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
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:38 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101