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
votes
1 answer

Can someone explain why the outcome isn’t the same?

I’m learning bash and Python. So I try to solve most questions with both Bash and Python. That’s how I ended up with trying to get the length of a string in both Bash and Python, and wc is giving back a different number. Searched the internet to…
Peter
  • 39
  • 2
-1
votes
3 answers

Substract number from wc cmd in one line

Let's suppose test.csv contains 10 lines. I'd like to put 9 into output.txt in one command line. I tried: cat test.csv | $(wc -l) - 1 > output.txt output.txt should contain 9.
user2856064
  • 541
  • 1
  • 8
  • 25
-1
votes
2 answers

using the pipe and word count (wc) then dress the result

I'd like to dress the output of a grep I'm doing. Imagine a file text.txt with a lot of text. Then I do the commands: grep fred text.txt | wc -l grep bob text.txt | wc -l grep james text.txt | wc -l I get the output: 12 3 4 What I would like to…
Brajesh
  • 271
  • 1
  • 3
  • 11
-1
votes
1 answer

WC API: Invalid JSON RETURNED

what am i doing wrong here?! It's two days since i've killed Google and stackoverflow... I can't figure it out :((( I've checked online the returned body json (didn't paste it here cause it's long) and is a valid json... where is the problem?! No…
Eugen
  • 1
  • 1
-1
votes
1 answer

How does this work to count number of lines in a file? no_of_lines=`<$file wc -l`

I can almost undestand why no_of_lines=`wc -l <$file` stores the number of lines in file. But how does no_of_lines2=`<$file wc -l` also give the same answer?
-1
votes
2 answers

Fastest way to count just the first X lines of output

I have a large terminal output from a tshark filter and I want to check if the number of lines (number of pakages in this example) reaches a threshold of X. The operation is done in a loop of many big files so I want to boost performance to the max…
Michael P
  • 603
  • 1
  • 5
  • 22
-1
votes
1 answer

Count unique words in all text files in directory, and delete those having less than 2?

This gets me the count. But how to delete those files having count < 2? $ cat ./a1esso.doc | grep -o -E '\w+' | sort -u -f | wc --words 1 $ cat ./a1brit.doc | grep -o -E '\w+' | sort -u -f | wc --words 4 How to grab the filenames of those that have…
Geoffrey Anderson
  • 1,534
  • 17
  • 25
-1
votes
1 answer

How to combine tree and wc -l?

I have folder base_dir with subfolders, each subfolder contain .jpg images, I want output similar to tree -L 1 base_dir, but with number of jpg images next to subfolder name, is it possible?
mrgloom
  • 20,061
  • 36
  • 171
  • 301
-1
votes
1 answer

How is it possible to implement a realtime version of wc?

I want a command(named rtwc) that acts like wc -c. it reads an input stream(stdin) and writes the number of bytes read after 1 second then update the number every one second. In fact it shows the progress of reading. This command is useful in a…
gopy
  • 328
  • 1
  • 9
-1
votes
1 answer

Getting process information of every process

I am trying to create a program that any normal user can run on windows and generate a process list of all processes, including the executable location. I have used CreateToolhelp32Snapshot() to get all process names, pid, ppid. But having issues…
user93938
  • 1
  • 1
-1
votes
3 answers

Can't use Linux wc on one-line file

I have a one-line file with no newline character at the end of the line. When i run the following: diff oneline-file.txt any-file.txt | wc -c I get: Warning: missing newline character in oneline-file.txt Why is this an error? How can i fix it? I…
JRomeo
  • 543
  • 1
  • 4
  • 20
-1
votes
1 answer

UnicodeEncodeError if piping output to wc -l

When running the code: #! /usr/bin/env python # -*- coding: UTF-8 -*- import xml.etree.ElementTree as ET print ET.fromstring('vägen').find('road').text Produces the…
cpaitor
  • 423
  • 1
  • 3
  • 16
-1
votes
1 answer

Java program returning int array with 3 elements (#of lines, # of words, # of characters) from a text fil

My code is using the read() function to "read" through a txt file one character at a time and needs to internally count the number of lines, words, and characters. Definitions of what is considered a line, word, and character: of characters = any…
-1
votes
1 answer

How to store total no. of lines in a variable in a shell script?

I'm recieving this in the error - syntax error near unexpected token `total_lines=$(wc -l < $extracted_log_path_value)' $extracted_log_path_value stores the path of the file which is correctly defined. I'm using simple shell script. No plugin is…
bosari
  • 1,922
  • 1
  • 19
  • 38
-1
votes
1 answer

Using grep and wc with wildcards on a file

Display: 1) number of students whose last name is Yang. My work: 1) grep "[Yang] [A-Za-z]* [A-D][+]* [A-Za-z]*" students.txt | wc -l Comment: Regex seems ok but outputs 6 instead of 3
geforce
  • 61
  • 6