wc command confusion


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers wc command confusion
# 1  
Old 09-06-2006
wc command confusion

Can somebody explain it to me that why wc gives more chars suppose
Ab.txt have two lines
qwer
qasd
then wc -c ab.txt will give 10.why not 8.okay may be it is taking count one for each line just in case but why echo "qwer"|wc -C gives 5.

Ok with \c it is returning 4. Smilie

Last edited by Dhruva; 09-06-2006 at 11:46 AM..
# 2  
Old 09-06-2006
newline

What you dont notice is a newline character at the end of each line. Do a
Code:
od -c filename

and see. Similarly try
Code:
echo "qwer"|od -c

To avoid a newline at the end of echo, check this
Code:
echo "qwer\c" | wc -l

Hope that helps
# 3  
Old 09-06-2006
HTML Code:
Ok with \c it is returning 4.
yes i figured it out.Thanks for your reply.
# 4  
Old 09-07-2006
Quote:
yes i figured it out.Thanks for your reply
What you found exactly?
# 5  
Old 09-08-2006
What i found is echo put newline character at the end of string and which can be omitted by using \c escape sequence.
\c output string without newline character.
similar thing can be achieved by echo -n but i dont have echo with -n option.

ksh's echo, does not have a -n option. sh's echo and /usr/bin/echo only have a -n option if the SYSV3 environment variable is set.
/usr/ucb/echo has -n option.
# 6  
Old 09-08-2006
If you are looking for a more portable method, perhaps use printf.
However, if you just want to find the size of a string, try ${#var}
# 7  
Old 09-08-2006
Thanks Ygor.honestly i was not aware of ${#var}.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Confusion in hash

Hi folks, If a declare a direct hash , then the hash element works fine. my %test = ("test",1); print %test; print "\n"; Here in the above, the name of the hash is predeclared... Suppose now I need to create the hash elements dynamically in the for loop. $test="hash"; my... (1 Reply)
Discussion started by: scriptscript
1 Replies

2. UNIX for Dummies Questions & Answers

Confusion with echo command under csh shell

HI, guys, I am having some problem with the echo command, so I want to echo some text to a file name loginFile, the result inside the loginFile should looks like: expect ">" so what I did is: echo "expect "">""" >> $loginFile but it just gave out: expect > The thing is I still need... (2 Replies)
Discussion started by: warmboy610
2 Replies

3. Shell Programming and Scripting

confusion in use of exit 0

hi i am new to shell scripting. i was going thru the part option and arguments. on this section i fail to understand the use of exit 0 in below example . #!/bin/sh USAGE="Usage: $0 " case "$1" in -t) TARGS="-tvf $2" ;; -c) TARGS="-cvf $2.tar $2" ;; *) echo "$USAGE" exit 0 ;; esac... (13 Replies)
Discussion started by: scriptor
13 Replies

4. Shell Programming and Scripting

Confusion with PS

Hello All, I have a problem in counting number of process getting run with my current script name.. Here it is ps -ef | grep $0 | grep -v grep This display just one line with the PID, PPID and other details when i print it in the script. But when I want to count the numbers in my... (11 Replies)
Discussion started by: sathyaonnuix
11 Replies

5. UNIX for Dummies Questions & Answers

[Query] Confusion of the Swap when using 'free -m' command

Hi All, I have just installed my first Linux server ( Ubuntu 11.10 ). I am sure I didn't allocate /swap , and double check by 'df -h', yes really no /swap but when I use 'free -m' , returned a "Swap" line as below. total used free shared buffers cached Mem: ... (3 Replies)
Discussion started by: joaming
3 Replies

6. Cybersecurity

LDAP; confusion

Hello, I hope all is well. Two issues that I am grappling with. One: Is this a true statement: (AIX, LDAP configured), even if authentication is configured with LDAP, the system would still need to be authenticated against local (/etc/passwd); incase of network failure? Two: I can log... (0 Replies)
Discussion started by: rsheikh
0 Replies

7. Solaris

Printer confusion

I have printer old about 5 year , but I can not determine which driver to use output of ls -al /usr/share/lib/terminfo/h -rw-r--r-- 1 root bin 961 Jan 22 2005 h1000 -rw-r--r-- 1 root bin 1002 Jan 22 2005 h1420 -rw-r--r-- 1 root bin 1009... (2 Replies)
Discussion started by: solaris_user
2 Replies

8. UNIX for Advanced & Expert Users

Mail command confusion

When i run this command on my linux machine: mail -s "CVS ALERT-CRITCAL" sandy@xyz.com The system hangs up producing a dead letter. What should i do to resolve this. I am using : mailx -s "CVS ALERT-CRITCAL" sandy@xyz.com This cammnd works fine on another Linux machine but says"... (14 Replies)
Discussion started by: bsandeep_80
14 Replies

9. UNIX for Dummies Questions & Answers

'tr' confusion

Good day, everyone! Could anybody explain me the following situation. If I'm running similar script: Var="anna.kurnikova" Var2="Anna Kurn" echo $Var | tr -t "$Var" "$Var2" Why the output is : anna KurniKova instead of Anna Kurnikova? :confused: Thank you in advance for any... (2 Replies)
Discussion started by: Nafanja
2 Replies

10. UNIX for Dummies Questions & Answers

ftp confusion

I'm an intern at a company that recently bought out another business. In doing so, they inherited a unix system that contains files which they need to retrieve. No one in the company, including myself, really understands or knows unix so please respond with the true assumption that I'm a unix... (1 Reply)
Discussion started by: intern
1 Replies
Login or Register to Ask a Question