Hi, I have collection of letters in a column such as:
AA5678
AA9873434
..
..
I am trying to find the number of charecters in each.
"echo "AA5678"|wc -c
7----------------> why does it give 7 instead of 6?
Hi, I have collection of letters in a column such as:
AA5678
AA9873434
..
..
I am trying to find the number of charecters in each.
"echo "AA5678"|wc -c
7----------------> why does it give 7 instead of 6?
It's counting the final line feed as well.
how do i avoid the line feed to give the correct value?
That depends on how you present the values - in a file? in a variable? echo
ing a constant? Mayhap you just subtract one?
Hi kvosu...
This might explain the reason:
OSX 10.14.3, default bash terminal.
Last login: Mon May 6 08:56:48 on console
AMIGA:amiga~> echo "" | wc -c
1
AMIGA:amiga~> echo "123456" | wc -c
7
AMIGA:amiga~> printf "" | wc -c
0
AMIGA:amiga~> printf "123456" | wc -c
6
AMIGA:amiga~> _
Deleted.
Double post by me.
awk does not consider the RS=\n=(line feed) character:
echo "AA5678" | awk '{print length}'
6
In case you have a shell variable, the ${#var} gives the length:
var="AA5678"
echo ${#var}
6