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
0
votes
3 answers

Count of products whose cost is greater than 10

I have file Product Cost a 10 b 20 c 30 I want to count no of products whose cost is greater than 10. I have used: awk '{$2>10}' myfile | wc -l but its not functioning — I get the result 0 instead of 2 which I am expecting. …
Aquarius24
  • 1,806
  • 6
  • 33
  • 61
0
votes
0 answers

bash command substitution issue with subshell

I was trying to prevent a script from being run by more than one user simultaneously and did not want to use commands only available on some OS'es or shells (pgrep, pidof, ...) and bumped into an issue that I am not sure whether it is a bug or…
brierand
  • 9
  • 2
0
votes
1 answer

How to check test command in Unix

I am just trying to check the alert.log file, if it is having the word (line? ed.) count greater than 4 and the word Time is there in it, then I will grep only for Time and it will print the latest timestamp. But if Time is not there, it should…
0
votes
1 answer

How do to wc command in if statement

There are other similar questions online out there, but I just couldn't figure out what's wrong with my code after trying those online suggestions. Below is my code: LineNum = `wc -l < /data/${INPUT:0:4}/${INPUT:4:2}/positions.$INPUT` if [2 -le…
walkens
  • 61
  • 1
  • 4
  • 11
0
votes
0 answers

wc and grep together for all files in a folder

Hi I want to count particular lines using grep for all files in a folder I know doing find . -name 'FileName' | xargs wc -l Helps with counting lines for all files. But I wonder how can I include grep in it. Ideally I want to do grep @ FileName |…
0
votes
1 answer

Word count program not working. Code sample From the Book The C-programming Language Ritchie & Kernighan

This is the code sample for the word counting program. But it's not working. When we execute it, after entering words it is supposed to display the results, but it is not producing anything.Anything missing in this code ? #include #define…
Krishnadas PC
  • 5,981
  • 2
  • 53
  • 54
0
votes
1 answer

count lines with different conditions using awk

I need to get the number of lines with 2 different conditions for 1 text file. The first condition is that values of the third column are smaller than 10 so I can do it by the following script: awk '$3<=10' DATA_File | wc -l The second condition…
Kredo
  • 23
  • 5
0
votes
1 answer

how to find the directory/sub directory having the highest number of file

I am trying to find a directory having highest number of files inside it. I am aware that I can find the number of files using: find -maxdepth 5 -type f | wc -l but this is only of use when I know which directory to check. I want to find that…
user2809888
0
votes
3 answers

Count number of lines after wrapped by terminal’s length

Suppose your tput cols (or COLUMNS) is equal to 100 and you have a plain text file foo.txt with a single line that is 120 characters long. If you wanted to count number of lines it contains you could do cat foo.txt | wc -l and unsurprisingly enough…
Ali
  • 1,396
  • 14
  • 37
0
votes
1 answer

How to format output for number of lines, words, characters for a file in bash?

I am trying to write a shell script which will count the number of lines, words and characters in Bash. echo "Enter file name" read file if [ -f $file ] then echo "The number of lines in $file are " echo $(wc -l…
0
votes
3 answers

Get first argument of wc -l myFile.txt

I'm counting the number of lines in a big file using wc -l myFile.txt Result is 110 myFile.txt But I want only the number 110 How can I do that? (I want the number of lines as an input argument in a bash script)
mcExchange
  • 6,154
  • 12
  • 57
  • 103
0
votes
1 answer

Bash: Using Number of Lines in File in Variable

I am trying to extract the number of lines from a file, and then use it in a variable. However, it keeps passing the file name, not the number of lines. I read through this question, but the examples are not working. for i in…
Adam_G
  • 7,337
  • 20
  • 86
  • 148
0
votes
1 answer

unix word count tool counting characters across multiple lines

How would I apply the word count tool to a task of this nature: Д е с я т ь д н е й I want to know how many characters appear but I want to ignore the white space in between the characters. How can I specify that in the unix word count…
user3803974
0
votes
2 answers

Bash script loop to count file size of all files in current directory?

Im very new to bash, and I have been given the task to write a bash script incorporating a loop that counts the byte size of all files in the current directory. I want to use du but Ive been told he wants to see wc as the main command used. As to…
0
votes
3 answers

Bash: displaying wc with three digit output?

conducting a word count of a directory. ls | wc -l if output is "17", I would like the output to display as "017". I have played with | printf with little luck. Any suggestions would be appreciated.