wc -c produces inconsistent count
by lucmove from LinuxQuestions.org on (#5MDQH)
I need to spot every line in a file whose length exceeds 40 characters. I am using the Fish shell:
Code:for i in (cat file.txt)
set n (echo $i | wc -c)
if test $n -gt 40
echo "$n $i"
end
endThe very first line in the output catches my attention because I have checked it manually and I know it's exactly 40 characters long. But it's present in the output and $n is printed as 41.
So I check it:
Code:$ gc | wc -c
40Mind you, "gc" is "getclip," a script I have made to capture the clipboard. If I just run "gc," the copied string is printed in the output, and it looks like just what I expect. I can't reveal the string because it's under a confidentiality agreement, but I can assure you it contains no weird symbol, only letters and a period symbol at the end.
Checking again:
Code:$ echo "(manually pasted string)" | wc -c
40In Fish script, -gt means "greater than." There is also -ge for "greater or equal." But I am using -gt.
Trying again:
Code:for i in (cat file.txt)
set n (echo $i | wc -c)
if test $n -gt 40
echo "$n $i"
end
endThe line is included in the output and $n is 41.
Any idea what is going on?
Code:for i in (cat file.txt)
set n (echo $i | wc -c)
if test $n -gt 40
echo "$n $i"
end
endThe very first line in the output catches my attention because I have checked it manually and I know it's exactly 40 characters long. But it's present in the output and $n is printed as 41.
So I check it:
Code:$ gc | wc -c
40Mind you, "gc" is "getclip," a script I have made to capture the clipboard. If I just run "gc," the copied string is printed in the output, and it looks like just what I expect. I can't reveal the string because it's under a confidentiality agreement, but I can assure you it contains no weird symbol, only letters and a period symbol at the end.
Checking again:
Code:$ echo "(manually pasted string)" | wc -c
40In Fish script, -gt means "greater than." There is also -ge for "greater or equal." But I am using -gt.
Trying again:
Code:for i in (cat file.txt)
set n (echo $i | wc -c)
if test $n -gt 40
echo "$n $i"
end
endThe line is included in the output and $n is 41.
Any idea what is going on?