Questions tagged [wc]

`wc` is a standard POSIX command that counts words, lines, and characters.

The wc utility reads one more files (or the standard input) and writes the number of lines, words, and characters to the standard output. If more than one file is given, then the total number of lines, words, and characters across all inputs will also be printed. There are also switches for controlling what parts should be counted.

Some versions of wc can differentiate between characters (which may be multi-byte depending on the encoding) and bytes.

References:

350 questions
3
votes
1 answer

wc -l and python line count differ

I'm wondering why a simple line count using bash is giving me a different number of lines than that computed using python (version 3.6) for the files given here (train_en.txt) and here (train_de.txt). In bash, I'm using the command: wc -l…
Vivek Subramanian
  • 1,174
  • 2
  • 17
  • 31
3
votes
6 answers

bash obtain wc -l number and display in one command?

I'm pretty sure this is going to be obvious, but currently im doing this: count=`find $dir -type f \( -perm -007 \) -print 2>/dev/null | wc -l` This gets me the number i want, but dosen't display anything on screen (although i chuck away error…
Sirex
  • 219
  • 4
  • 22
3
votes
1 answer

Insecure $ENV{ENV} while running with -T switch

When I try the last example from perlfaq5: How-do-I-count-the-number-of-lines-in-a-file? I get an error-message. What should I do to get the script working? #!/usr/local/bin/perl -T use warnings; use 5.012; $ENV{PATH} = undef; my $filename =…
sid_com
  • 24,137
  • 26
  • 96
  • 187
3
votes
1 answer

Difference in count with ps | wc

When I print the processes, I get: $ ps --no-headers 12961 pts/0 00:00:00 bash 16676 pts/0 00:00:00 ps So, their are only two processes. However, when I do: $ ps --no-headers | wc -l 3 Any idea why ?
Yohan Obadia
  • 2,552
  • 2
  • 24
  • 31
3
votes
5 answers

How to count the number of numbers/letters in file?

I try to count the number of numbers and letters in my file in Bash. I know that I can use wc -c file to count the number of characters but how can I fix it to only letters and secondly numbers?
K.Dote
  • 31
  • 1
  • 3
3
votes
1 answer

wc -l returning 0 on a non-empty file

I downloaded a JSON file using Curl on my server from https://api.data.gov/ed/collegescorecard/v1/schools?api_key=[my_API_key] (I have uploaded the file to TinyUpload if you want to play around with it.) The downloaded file is 1.5MB and has a very…
Matthew Herbst
  • 29,477
  • 23
  • 85
  • 128
3
votes
1 answer

How Count Korean Word Block using Unix/Linux Commands?

Korean consists of word blocks (e.g., 가, 나, 다 라, etc.). I need a way to count these word blocks. For instance, the word 바다 (sea) should return 2. but wc -w will return 1 wc -c will return 7 So these options won't work for me. I would appreciate…
Eungi Kim
  • 67
  • 6
3
votes
3 answers

How does the wc -c in linux work?

Why the number of characters is 4? echo abc|wc -c Output 4 The output should be 3, because the number of characters is 3.
Pankaj Mahato
  • 1,051
  • 5
  • 14
  • 26
3
votes
3 answers

Capturing output and counting its lines

I'd like to run a find command and then count the lines of the output as well as give out the output of the result. My straight-forward approach was this: output=$(find ...) lines=$(echo "$output" | wc -l) echo "$output" But unfortunately using…
Alfe
  • 56,346
  • 20
  • 107
  • 159
3
votes
2 answers

I'm trying to use tr with multiple sets and not sure how

I have used: tr -dc [:alpha:] < $fileDoc | wc -c to count all letters, tr -dc ' ' < $fileDoc | wc -c to count all spaces, tr -dc '\n' < $fileDoc | wc -c to count all new lines in a text document. What I would like to do now is to do now is count…
user3347022
  • 259
  • 2
  • 12
3
votes
2 answers

Finding how many lines are different between two files

Write another script that uses a command pipeline to take 2 files as parameters, compare their contents and count how many lines are different. You will use wc –l to count the differing lines. I have tried everything I can think of to do this. I…
user2234688
  • 79
  • 1
  • 5
2
votes
1 answer

Number of lines from a gzip file (AIX)

How to count the number of lines in a gzip file? wc -l can be used to get the number of lines from a normal file but what if it is a .gz file ??
Govind Kailas
  • 2,645
  • 5
  • 22
  • 24
2
votes
1 answer

Why do I have different line counts?

I made these different programs in different programming languages to count the number of lines of a file, and it turns out that the output differs according to the program, but the strange thing is that some programs have the same results, I was…
Sebasos
  • 41
  • 4
2
votes
2 answers

Why does the ouptut of wc -l differ if executed in backticks?

I just encountered that the output of wc -l differs when called directly or enclosed in backticks. For example: pgrep bash | wc -l would output 1, as there is one bash process running. But enclosing this command in backticks echo `pgrep bash | wc…
Mike
  • 21
  • 1
2
votes
3 answers

How can I find the number of 8 letter words that do not contain the letter "e", using the grep command?

I want to find the number of 8 letter words that do not contain the letter "e" in a number of text files (*.txt). In the process I ran into two issues: my lack of understanding in quantifiers and how to exclude characters. I'm quite new to the Unix…
doelie247
  • 124
  • 8