Terminal command that outputs line/word/byte count for files or standard input
Questions tagged [wc]
15 questions
24
votes
3 answers
"wc -c" and "wc -m" command in linux
I have a text file, its content is:
i k k
When I use wc -m to count character numbers on this file, the result is 7.
Question 1: But why did I get 7, shouldn't I get "6" supposing that it counts the "end-of-line" character?
Question 2: How exactly…
SWIIWII
- 544
12
votes
4 answers
When counting lines with wc, don't print an error whenever is a directory
I want to count the total number of lines in all /etc files but not the files in the sub directories, so I typed: wc -l /etc/* | tail -1 and the output is like:
xxxx is a directory
yyyy is a directory
total 1752
My question is, how can I rid of…
Hamza
- 387
10
votes
3 answers
How can I count characters of text copied in the clipboard?
I select some text and copy it using Ctrl + c. Now the text is in the system clipboard. I can paste this code using
Ctrl + v in a file and run wc for the file to check the count of characters, lines and words.
But if I want to count the characters…
alhelal
- 2,741
9
votes
5 answers
How to count the occurrence of specific string on a specific line in a file?
I know I can use wc to return the total number of words (and lines) in a file using:
wc
Is there a way to return the count for a specific string on a specific line of a file like the following:
wc - -…
Don
- 229
- 1
- 3
- 16
9
votes
4 answers
How to remove the filename from wc -l output?
I want to count the number of lines in a file using wc -l but only output the number, without the following space and filename.
Edit from comments: The filename may have numbers in it.
Currently if I do:
wc -l /path/to/file
On a file with 176…
Arronical
- 20,241
6
votes
4 answers
Count number of different name in a file
I want to count the number of different name in a text file of this presentation:
2008 girl Avah
2009 girl Avah
2008 girl Carleigh
2011 girl Kenley
2012 boy Joseph
2013 boy Joseph
2014 boy Isaac
2014 boy Brandon
So basically I want to skip the…
John Baptist
- 351
6
votes
1 answer
Why there is a difference between the output of 'echo $VAR | wc -c' and 'echo ${#VAR}'?
I'm working on a Bash script and the length of the string contained in a certain variable is one of my conditions. The current string is W5u7TBTzF17GGFV8DBJHvgAAAAI. Initially I've count the string length by the help of wc -c:
$…
pa4080
- 30,621
5
votes
1 answer
`wc -c` gives un expected results?
I have a .log file which is a binary file(BSC0000.log). So Viewed it in a HEX viewer(OKteta) and exported it directly in to a string(split_space.txt). With spaces in the middle as
00 DF 00 45.
The thing is that when I counted the characters in both…
Laksith
- 169
5
votes
1 answer
Why `wc -m` counts 1 character more?
Why wc -m counts one character (symbol) more from here-string (<<<)
Here is example:
$ TEST_STR="askubuntu"
$ echo "$TEST_STR"
askubuntu
$ wc -m <<<"$TEST_STR"
10
It is saying 10, but actually there is only 9 symbols.
The same problem appears for…
c0rp
- 10,010
5
votes
2 answers
How can I pipe the result of the wc command into an arithmetic expansion?
I want to run wc -l and use the result in an arithmetic expansion. In other words, I want to do something like this:
wc -l (now somehow pipe/pass the result of this to) $((2 + result of wc command))
How can I do this?
Context
In my ~/Pictures…
4
votes
4 answers
Problem with listing a directory to grep
grep seems broken on my machine. Reinstalling it does not help. A reboot does not help. The first two lines create a file containing arbitrary text and the input is terminated with the control-D character.
ls -1 means list in one column. A example…
H2ONaCl
- 10,039
1
vote
2 answers
counting in directory
I would like to know what the difference is between:
$ ls | wc -l
and
$ ls > foo
$ wc -l < foo
when counting all files in the current directorys. And why does the second one gives me one file more.
MassU
- 11
1
vote
2 answers
counting specific file in directory
Let assume, I need to count every file in directory which ends with o. (for example ab12.14o, 70010340.09o). Which command I need to use?
I tried ls *.o | wc but it doesn't work.
deepblue_86
- 1,246
0
votes
1 answer
script of reading one type of files in multiple directory
I have the Directory like 2018-01-10, 2018-02,10 and so on. In each directory it contains .CUD and .CUR files. I want the number of data (i.e. wc -l) which are in .CUD files only.
I used following command:
for D in /; do
wc -l ${D}/ >…
-1
votes
1 answer
Editing wc -l src Output
I am new to the Topic and working on a few bash commands.
I am stuck at a task where i Need t ouput my result in a specific Format.
wc -l folder/*
The Output gives me:
0 folder/file1
3 folder/file2
3 total
I would like to have only the total…
Yohnson
- 1