WC command Issue


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers WC command Issue
# 1  
Old 05-27-2009
WC command Issue

Hello Guys...

I am a newbie to Unix. I am having a requirement, Like in a file, I want to count the number of characters,

I used wc -c and wc -m, But both are giving the byte count instead of character count.

Please help me guys... Its very very urgent.

Really appreciate ur help..

Mahesh..
# 2  
Old 05-27-2009
that's strange. the man page says that -c gives byte count and -m gives character count
Code:
       -c, --bytes
              print the byte counts

       -m, --chars
              print the character counts

what's the character encoding of the file?
# 3  
Old 05-27-2009
the file is like this

cat file1

this is mango
this is banana
this is apple
this is grape
this is pineapple
this is orange
this is watermelon



I used wc -c and wc -m and it is giving the same thing,
Code:
[mraghunandanan@localhost SHANKU]$ wc -c <file1
109
[mraghunandanan@localhost SHANKU]$ wc -m <file1
109
[mraghunandanan@localhost SHANKU]$

Please resolve this problem....

Last edited by Yogesh Sawant; 05-28-2009 at 07:34 AM.. Reason: added code tags
# 4  
Old 05-27-2009
haha, sorry but this is not an issue. I copied and pasted exactly what you had in file1 and ran the same tests and came up with the same results. I also did a stat on it and it IS 109 bytes.

Code:
-bash-3.2$ stat file1
  File: `file1'
  Size: 109             Blocks: 8          IO Block: 4096   regular file

Of course, some of the information was removed, but just showing that the information is correct, and that there is no error.

Of course the internet is a wonderful tool, so you can start investigating like this..

Google.com - search for bytes (or wikipedia.org and save a step), near the top "Historically, byte size was determined by the number of bits required to represent a single character from a Western character set. ".

Western character set? OH WHAT IN THE HECK IS THAT!? Oh lordy. Time to search the intertubez again. To save you a few steps: ISO/IEC 8859-1 - Wikipedia, the free encyclopedia

So A-Za-z0-9, most symbols, are going to be in that set (1 byte in size). I've even been testing!
# 5  
Old 05-28-2009
If you want to know the number of characters in the file excluding the line terminating characters which are normally included in "wc -c":

Code:
cat file1 | tr -d '\n' | wc -c

# 6  
Old 05-28-2009
Quote:
Originally Posted by methyl
If you want to know the number of characters in the file excluding the line terminating characters which are normally included in "wc -c":

Code:
cat file1 | tr -d '\n' | wc -c

UUOC
Code:
tr -d '\n' < file1| wc -c

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Issue with awk command

I am new to unix.I have a requirement to get few fields from the log file as below. Log app9/cc-gr_base.log.2017-07-19.gz: hostname 1500523166993 NA:NA:NA http-nio-8080-exec-56 INFO Points balance from MIS for user with userId: 19651069, first name: DEREK RICHARD and last name: BOUDREAU is... (3 Replies)
Discussion started by: nextStep
3 Replies

2. Shell Programming and Scripting

Command issue

I am on Linux LXLE. I been trying to change directories and opens folders and files. 1. I cd /home file 2. then user (/home/teak/) Then I try to open the Document file, wouldn't it be /home/teak/doument? . It responds not a directory. So how would I open the document file, or not... (3 Replies)
Discussion started by: teak
3 Replies

3. Shell Programming and Scripting

Variable value substitution issue with awk command issue

Hi All, I am using the below script which has awk command, but it is not returing the expected result. can some pls help me to correct the command. The below script sample.ksh should give the result if the value of last 4 digits in the variable NM matches with the variable value DAT. The... (7 Replies)
Discussion started by: G.K.K
7 Replies

4. UNIX for Dummies Questions & Answers

rm command issue

Hi, Getting the below error. rm *.txt bash: /usr/bin/rm: Arg list too long I understand the error is because there are lakhs of .txt file. Any fix ? (16 Replies)
Discussion started by: mohtashims
16 Replies

5. Shell Programming and Scripting

issue in mail command

I have used the mail command from the command line for sending mail from one machine to anther machine. Example: mail -s "Test" thillaselvan@xxx.co.in Testing But the mail is not getting received. I have checked the logs in the following file. tail -f /var/log/exim4/mainlog It is... (0 Replies)
Discussion started by: thillai_selvan
0 Replies

6. Shell Programming and Scripting

Issue with command tr.

Hi, I am using tr command like below: cat file_name | tr -c "" "" > output_file When i run my script from command mode, it is working fine. I scheduled my job in autosys. When the job runs at specified I am getting below Error: tr: when translating with complemented character... (5 Replies)
Discussion started by: Karteek
5 Replies

7. Shell Programming and Scripting

Issue with WC command

I am trying to show out the character count of a file if greater than 500 characters. When I do the -m its show the size of the file and not the characters in the file. Where am I getting confused? Or is -c and -m the same thing? Code is below if ; then echo "Char... (3 Replies)
Discussion started by: tvb2727
3 Replies

8. Shell Programming and Scripting

dd command issue

dd if=/dev/zero of=/var/images/abc.img bs=1M count=0 seek=2097152 dd: truncating at 2199023255552 bytes in output file `/var/images/abc.img': File too large The dd commad fails here saying its truncating if I try same command with less value for seek it works dd if=/dev/zero... (3 Replies)
Discussion started by: amol28kulkarni
3 Replies

9. UNIX for Dummies Questions & Answers

cp command issue.

All, I have files in directory,when i try to overwrite those files it gave operation not permitted error. I am using same group user (ina2) while overwritng this file. Sample file : -rw-rw-r-- 1 ina1 indev 316 Jun 06 13:44 ONCTEST.dat Error: cp: /proj/out/ONCTEST.dat: Operation... (4 Replies)
Discussion started by: sai_nj
4 Replies

10. HP-UX

Tar command issue

I made tar file having file names more character( up to 50). When i extract file in Linux it extracts fine.. but in HPUX all file name which are more than 24 are trimed to 24 characters. i m using "tar -xvf xx.tar" i read some O and N option for New posix and Old but didnt got. :confused: ... (2 Replies)
Discussion started by: ajayyadavmca
2 Replies
Login or Register to Ask a Question