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

Count occurrence of files with an odd number characters in the filename

I'm trying to do a script that counts all the files in the system that have a name with a odd number of characters, only the name not the extension. somebody can help me? I've done this but it doesn't work find /usr/lib -type f | cut -f 1 -d '.' |…
1
vote
8 answers

using cut command in bash

I want to get only the number of lines in a file: so I do: $wc -l countlines.py 9 countlines.py I do not want the filename, so I tried $wc -l countlines.py | cut -d ' ' -f1 but this just echo empty line. I just want number 9 to be printed
eagertoLearn
  • 9,772
  • 23
  • 80
  • 122
1
vote
2 answers

bash -gt command with pgrep & wc

I'm trying to run [ pgrep mongo | wc -l -gt 2] to see if there are more than 2 mongo processes running, but I keep getting this error -bash: [: missing `]' I feel like I'm missing something simple here. Thanks!
Shail Patel
  • 1,764
  • 5
  • 30
  • 46
1
vote
1 answer

wc character count seems inflated by 1

When I try this: echo "hi" | wc -c I'd expect a character count of 2, but I actually get 3. Can someone explain why it isn't 2?
Magnus
  • 10,736
  • 5
  • 44
  • 57
1
vote
3 answers

Shell script to read a list of words and compute their counts in a corpus.

I need to write a command line script in linux to do the following: read a list of words from a text file (one word per line). say w_i for each w_i computes the word count in a different text file. sum over these counts some help here would be…
MAZDAK
  • 573
  • 1
  • 4
  • 16
1
vote
1 answer

How to make own version of wc utility?

Do you know how to make your own wc utility or any tutorials which will help you make one. We have to make our own wc utility for school which: -uses command line options -reading text from file -counting the number of characters, words and lines in…
Floyd Bostan
  • 141
  • 1
  • 1
  • 4
1
vote
0 answers

ashx and windows authentication

i have deploye my ashx service.when i try to access it using belwo code i got error 401 Unauthorised System.Net.WebClient webClient = new System.Net.WebClient(); webClient.UseDefaultCredentials = true; …
1
vote
2 answers

words counting in file like linux wc command in C

I am trying to write something that works like the Linux command wc to count words, new lines and bytes in any kind of files and i can only use the C function read. I have written this code and i am getting the correct values for newlines and bytes…
Youssef Khloufi
  • 685
  • 3
  • 13
  • 24
0
votes
3 answers

print search term with line count

Hello bash beginner question. I want to look through multiple files, find the lines that contain a search term, count the number of unique lines in this list and then print into a tex file: the input file name the search term used the count of…
user964689
  • 812
  • 7
  • 20
  • 40
0
votes
2 answers

count number of occurences in linux directory based on date value

So I have quite a bit of files that I want to to check the file count of based on date, but the thing is dates overlap in the files sometimes. For example a file could look like this issue_date cert_id serial 2023-05-14…
Alex
  • 211
  • 1
  • 11
0
votes
4 answers

Word count command returning incorrect row count for CSV files

I am running the following command to count the number of rows in a CSV file: wc -l filename.csv Sometimes the row count is correct and other times it is 1 less than the actual count. All of the files are in the same format with the same header…
Captain Caveman
  • 1,448
  • 1
  • 11
  • 24
0
votes
0 answers

WooCommerce - Send Order details and redirect to PHP Script

I have a problem and I don't really know how to solve it. I have a PHP form, hosted on another site outside of my woocommerce. And I need to make a payment gateway, which redirects to my PHP site and send the order data. but I don't understand how I…
0
votes
1 answer

How to list number of lines inside each file listed by the ls command?

I am using the bash ls command as follows: ls -S -l *usc*.vhd This lists all the files that have the letters usc in its name and ends with .vhd extension. Now, I also need the output to print how many lines there are in each file. Is this possible…
quantum231
  • 2,420
  • 3
  • 31
  • 53
0
votes
1 answer

How can pipes and grep and wc be combined to just give a count of the phrase “syntax ok”

How can pipes and grep and wc be combined to just give a count of the phrase “syntax ok” Something like the following… cd /usr/IBMIHS/bin/ | apachectl -t -f /usr/IBMIHS/conf/AAA/httpd.conf | apachectl -t -f /usr/IBMIHS/conf/AAA/siteAA.conf | grep…
paulhr
  • 339
  • 4
  • 17
0
votes
0 answers

Why is my script telling me there's a process running when it's actually not?

func () { local arrayOfParams=$@ local CMD="ps aux | grep -v grep" for item in ${arrayOfParams[@]}; do local CMD="$CMD | grep -e $item" done echo "Current process PID : $$" echo "`date`: CMD is…
user91991993
  • 705
  • 5
  • 11