Hi All,
I have a small queries to get the character count
i tried with wc -c
and wc -m
but its not returend current result
For eg:
wc -c
wc -m
echo "Name" | wc -c
result: 5 but actually it should returned 4
Help me on this to ge the correct one.
Thanks!
---------- Post updated at 09:22 AM ---------- Previous update was at 09:12 AM ----------
wc -c
Aia
2
echo adds a newline char
echo "Name" | od -bc
0000000 116 141 155 145 012
N a m e \n
Five then
Hi Aia,
I want to get the word count without new line character "\n"
for eg
echo "Name"
It should retruned 4 instead of 5
Aia
4
If your version of echo supports it you might try with the -n
flag to suppress that newline.
echo -n "Name" | wc -c
Otherwise use printf
printf "Name" | wc -c
Just subtract wc -l
from the value returned:
$ printf "one\ntwo\nthree\four\n" | wc -c
18
$ printf "one\ntwo\nthree\four\n" | wc -l
3
So your count is 15 (18 - 3)
or delete the newline chars:
$ printf "one\ntwo\nthree\four\n" | tr -d '\n' | wc -c
15