Doubt


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Doubt
# 1  
Old 11-24-2010
Doubt

Hi ,

Struck with one basic question.

Iam expecting word count of 4 where "wc" is showing as 5 .

Code:
# echo "abcd" | wc
1 1 5

# echo abcd | wc
1 1 5


Last edited by Scott; 11-24-2010 at 11:19 AM.. Reason: Code tags
# 2  
Old 11-24-2010
Doubt

Code:
harsh@harsh-desktop:~$ echo "abcd" | od -bc
0000000 141 142 143 144 012
          a   b   c   d  \n

As you can see echo adds a newline at the end of the string echoed so you get 5 as the number of characters

Last edited by pludi; 11-24-2010 at 11:38 AM..
# 3  
Old 11-24-2010
Hi Scott,

when it is not quoted , then "wc" should dispaly 4 right
# 4  
Old 11-24-2010
Doubt

Code:
harsh@harsh-desktop:~$ echo abcd | od -bc
0000000 141 142 143 144 012
          a   b   c   d  \n

Quoted or not quoted.. newline is added to the end of the string.

Last edited by pludi; 11-24-2010 at 11:38 AM..
# 5  
Old 11-24-2010
Quote:
Originally Posted by penchal_boddu
Hi Scott,

when it is not quoted , then "wc" should dispaly 4 right
I changed my post about three times before I finally gave up and deleted it Smilie

It's the newline character. That's why there are 5.

Without the newline...
Code:
$ printf abcd | wc
       0       1       4

# 6  
Old 11-24-2010
Thank to Scott and Harsha !!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Doubt

in my shell script requirement is to search and replace the file with variable so i use the following command sed -i "s/abc/$SCHEMA/g" table.sql later when the script runs sqlplus username/pwd@Table& this & is not letting the variable to replace the value inside the file .please let me know... (1 Reply)
Discussion started by: bhuvan1
1 Replies

2. Shell Programming and Scripting

Doubt..

Hi experts, In one of our code we have used some command like this. name=${name##*/} Can someone please let me know what exactly it does? Thanks & Regards, Sathya V. (1 Reply)
Discussion started by: Sathya83aa
1 Replies

3. Red Hat

Doubt

How to create a file with specific size in RHEL6 (1 Reply)
Discussion started by: Sashi Kanth A
1 Replies

4. Ubuntu

Doubt

hi ,, i am new for this.. i want to know abt linux os.. which version is best for it industry.. please suggest me..:cool: (1 Reply)
Discussion started by: c vignesh kumar
1 Replies

5. Shell Programming and Scripting

Doubt

Hi, I have a file with multiple entries and I have calculated the percentages. Now I want to know how many of my entries are there between 1-10% 11-20% and so on.. chr1_14401_14450 0.211954217888936 chr1_14451_14500 1.90758796100042 chr1_14501_14550 4.02713013988978... (1 Reply)
Discussion started by: Diya123
1 Replies

6. UNIX for Advanced & Expert Users

doubt in df -h

in my parition i hav parition like this Filesystem Size Used Avail Use% Mounted on /dev/sda2 24G 22G 756M 97% / /dev/sda5 248G 1.2G 234G 1% /else /dev/sda1 965M 24M 892M 3% /boot tmpfs 7.0G 0 7.0G 0%... (1 Reply)
Discussion started by: ponmuthu
1 Replies

7. Shell Programming and Scripting

One doubt

Hi, Can i use the shell script like this? When i am running the script it is hanging not giving me any output. I can redirect the output and then i can do the manipulations also but why this one is wrong. I am confused we can do like this or not.. #!/usr/bin/ksh for line in `top` do... (2 Replies)
Discussion started by: namishtiwari
2 Replies
Login or Register to Ask a Question