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
2 answers

Bash - Filtering lines according to a condition

I have a file that contains some lines as: @SRR4293695.199563512 199563512 CAAAANCATTCGTAGACGACCTGCTCTGTNGNTACCNTCAANAGATCNGAAGAGCACACGTCTGAACTCCAGTCAC +SRR4293695.199563512 199563512…
Maria
  • 43
  • 4
0
votes
2 answers

WC Fields Factory Plugin minDate

I'm using this plugin called WC Fields Factory. I have a datePicker on my "Single product" page on woocommerce so people can book in. I am trying to disable 48 hours (minDate:2) but I can't seem to make it work. I've tried so many examples, does…
Eazy
  • 331
  • 1
  • 3
  • 7
0
votes
0 answers

Count all integers from a file using grep

I have a file with contents like this: 9989 -23. An integer: 23 Number 9090 is cool. 22.33 is not a valid integer 22a33 -111 I run the command grep -E '\b[-+]?[0-9]+\b' file.txt This command looks for leading + or - and then keeps looking only for…
Divyat
  • 151
  • 14
0
votes
4 answers

Why is my wc implementation giving wrong word count?

Here is a small code snippet. while((c = fgetc(fp)) != -1) { cCount++; // character count if(c == '\n') lCount++; // line count else { if(c == ' ' && prevC != ' ') wCount++; // word count } …
theprogrammer
  • 1,698
  • 7
  • 28
  • 48
0
votes
1 answer

Centos7: reading binary files, using wc for number of names

My task is to count the number of names in a backup file I have made using wc and a pipe, display the first 5 names, then display the last 5 names. I have tested the 'strings' command to view the file, however wc will simply output a never ending…
0
votes
1 answer

Unix command to count a given string and print with filename

i have a multiple files in a folder. i want to read the files to count a word present and print with filename. for example: numeric value is matching count of the string filename string1 string2 file1 5 1 file2 3 7
0
votes
1 answer

different count using ps and wc to check if service is running in bash

I have a small script to check if a service is running in bash #!/bin/bash countlines=""$(ps -ef | grep netdata | grep -v grep | wc -l) echo $countlines >> mylog.log if [ ${countlines} -lt 3 ];then sudo /bin/systemctl restart netdata fi The…
Forge
  • 1,587
  • 1
  • 15
  • 36
0
votes
2 answers

Storing wc into a variable saves the complete file

I am trying to store the output of wc into a variable but have some problems first i cannot use COUNT=$(ls -1 file.log | wc -l) because i get the error: Variable Syntax. Second if i do something like this COUNT='ls -1 file.log | wc -l' then i…
Ram
  • 1
0
votes
3 answers

Hidden line in file?

I have a UTF-8/no BOM file (converted from ISO-8859-1) that has 31214 lines. I have already run dos2unix on the file. When I open it in notepad++, I see a blank line underneath. When I remove this blank line, the line count reduces by one. I save it…
Goiko74
  • 1
  • 1
0
votes
2 answers

Count non blank lines

I am using wc -l to count the number of lines I get as output from docker ps command. Sometimes there are no containers in the list and it just gives empty line but wc -l counts that as well and says the answer as 1. How can I avoid this
ambikanair
  • 4,004
  • 11
  • 43
  • 83
0
votes
1 answer

How to take count some data of a file which is in archived folder?

I have a archived folder which contain some files, from one of those files I want to take count of 31 delimiter. How to get count without unzipping folder? archived folder name =mug.tar, file name = APR_17 Below is how to take count | awk -F "|"…
Prafull
  • 17
  • 3
0
votes
2 answers

Performance of wc -l

I ran the following command : time for i in {1..100}; do find / -name "*.service" | wc -l; done got a 100 lines of the result then : real 0m35.466s user 0m15.688s sys 0m14.552s I then ran the following command : time for i in {1..100}; do…
shrimpdrake
  • 1,476
  • 2
  • 14
  • 25
0
votes
3 answers

I want to check if some given files contain more then 3 words from an input file in a shell script

My first parameter is the file that contains the given words and the rest are the other directories in which I'm searching for files, that contain at least 3 of the words from the 1st parameter I can successfully print out the number of matching…
Róbert Nagy
  • 6,720
  • 26
  • 45
0
votes
2 answers

How to make sh display number of lines while running?

"Append to the file the following commands that when this file is executed it will do the following: 4) Display This file has x lines 5) Display This file has x words 6) Display this file has x bytes " I know the command is the variations of wc, but…
0
votes
2 answers

Printing a line in a certain percentile of a larg text file

I am looking for a single line command to print a line in a certain percentile of a large text file. My preferred solution is something based on sed, wc -l, and/or head/tail as I already know how to do that with awk and wc -l. To make it more…
user2517676
  • 969
  • 6
  • 15
  • 25