LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2004, 07:05 PM   #1
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Rep: Reputation: 30
Bash quirk?


K here's an interesting thing I just found (bags not manually counting words lol)...

if you run either of these you would expect the same result, right?

Code:
wc -w foo.c

cat foo.c | tr ' ' '\n' | wc -l | awk '{print $1}'
but if you run it on a big file it gives you a complete different number... (i.e. I have a project I'm writing, the 1st statement gives me 315 words, the second 602...)

Is there any difference in the statements?
 
Old 02-06-2004, 07:29 PM   #2
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
cat foo.c | tr -s ' ' '\n' | wc -l | awk '{print $1}'
 
Old 02-06-2004, 07:30 PM   #3
snacky
Member
 
Registered: Feb 2004
Distribution: Debian
Posts: 286

Rep: Reputation: 30
well done :-)
 
Old 02-06-2004, 08:05 PM   #4
h/w
Senior Member
 
Registered: Mar 2003
Location: New York, NY
Distribution: Debian Testing
Posts: 1,286

Rep: Reputation: 46
i like snacks too, fank you.
 
Old 02-06-2004, 08:16 PM   #5
AMMullan
Member
 
Registered: Sep 2003
Location: United Kingdom
Distribution: Ubuntu, Arch
Posts: 438

Original Poster
Rep: Reputation: 30
k well that gave me 330 words (compared to wc -w with 315) - wonder what wc counts?

I have a feeling wc might leave out symbols or something...
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Quirk with Kmail floydking General 0 11-04-2005 05:09 PM
iptable quirk? Jukas Linux - Networking 4 09-24-2005 05:18 PM
startup quirk chroot Debian 3 09-03-2003 10:49 PM
PCI quirk Tenchi147 Slackware 0 06-04-2003 08:56 PM
samba quirk -- formfeeding DaFrEQ Linux - Software 6 01-27-2003 01:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration