LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-06-2010, 11:54 AM   #1
Snake_Eyes_
LQ Newbie
 
Registered: Dec 2009
Posts: 6

Rep: Reputation: 0
Why does `wc -m` output one too many?


# echo "foobar" > /tmp/word
# cat /tmp/word | wc -m
7

I want to print the number of characters in the file.
Why does it output 7? Am I missing something obvious?

manpage:
-m, --chars
print the character counts
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 04-06-2010, 12:02 PM   #2
Fingers of Fudge
LQ Newbie
 
Registered: Aug 2007
Distribution: Slackware 13.0
Posts: 14

Rep: Reputation: 1
Maybe there's an end of file character.
 
Old 04-06-2010, 12:54 PM   #3
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Fedora38
Posts: 6,147

Rep: Reputation: 435Reputation: 435Reputation: 435Reputation: 435Reputation: 435
Quote:
Maybe there's an end of file character.
It is is a <NL>:
Code:
tred@pc:~$ echo "foobar" > /tmp/word
tred@pc:~$ hexdump /tmp/word
0000000 6f66 626f 7261 000a
=        o f  b o  r a   <NL> 
=        f o  o b  a r   <NL> when you have byte-swapped
Try it again with echo -n "foobar" > /tmp/word

Code:
man echo....
DESCRIPTION
       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline
 
3 members found this post helpful.
Old 04-06-2010, 01:03 PM   #4
Snake_Eyes_
LQ Newbie
 
Registered: Dec 2009
Posts: 6

Original Poster
Rep: Reputation: 0
Awesome!!!! Works, thanks.
 
  


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
[SOLVED] Getting xdebug 2.0.5 switch text output to html output lhorace Linux - Server 1 11-01-2009 05:23 PM
How to redirect the output of exec command output in perl? sudhap85 Linux - Newbie 3 08-28-2009 03:35 PM
Grep on output of command returns all output traigo Linux - Newbie 2 02-24-2009 05:15 PM
ps -eH | grep java output in a active passive clustered output johnkalikavunkal Linux - Server 2 01-30-2009 11:21 PM
the sound gives output when using mic but no output when run a music file medo Debian 0 04-19-2004 07:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:40 PM.

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