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

Using ksh to return the file with the most lines in a directory

I am scripting a ksh file where I am looking to return the file with the most number of lines in a directory. The script can only take one argument and must be a valid directory. I have the 2 error cases figured out but am having trouble with the…
hanktank45
  • 19
  • 3
0
votes
2 answers

append output of each iteration of a loop to the same in bash

I have 44 files (2 for each chromosome) divided in two types: .vcf and .filtered.vcf. I would like to make a wc -l for each of them in a loop and append the output always to the same file. However, I would like to have 3 columns in this file:…
0
votes
1 answer

time difference between counting lines in a file from python/unix

im using 'wc -l' for file with 50 columns and 3000 records to count the lines in python code itself below cmd='wc -l /path of file' status,output=command.getstatusoutput(cmd) and again i tried using the below one in python row_count=sum(1 for…
narman12
  • 43
  • 8
0
votes
2 answers

extract the total count line (wc -l) number in shell

I am trying to figure out how to extract the last total count number when I use "wc -l" on multiple files under a directory. For example: currentDir$ wc -l *.fastq 216272 a.fastq 402748 b.fastq 4789028 c.fastq 13507076 d.fastq …
Helene
  • 953
  • 3
  • 12
  • 22
0
votes
1 answer

How to make wc work recursively WITHOUT FIND

I want to count letters in files. They are on different levels. I used wc -m `ls -R` however, it works only for files that are in current directory. I need either to list full paths or extend wc scope. I tried using ls -d -1 $PWD/* as several…
0
votes
2 answers

How to specify NUL-terminated names of files for wc --files0-from=F

I need to test wc with --files0-from=F flag, but I don't know how to write a file that contains NUL-terminated file names? Whatever I try, it merges the file names together and outputs: wc: '1.txt2.txt': No such file or directory wc: '1.txt…
ivanacorovic
  • 2,669
  • 4
  • 30
  • 46
0
votes
1 answer

How to assign the total number of lines in a file to the size variable for an array in a bash script?

i've been trying to get something like this to work for a while now but I keep running into little imperfection that mess up building my array. #!/bin/bash There are a total of four lines in this repo file repofile=~/Home/Documents/repoKali I type…
arcad31a
  • 1
  • 1
0
votes
0 answers

how to execute ls | wc -w using pipes?

i am trying to create a shell program to execute piped command. When i call ls from forked child & wc from parent it works fine. but if i call wc also from forked child parent keeps on waiting (i don't know why this is happening). void…
0
votes
1 answer

running multiple execve functions in one c++ file

I have to write a c++ program which "counts the number of lines, words and the number of bytes from a text file", all of which must be in a new line. I have to use the wc command in my c++ program. I have managed to get the number of lines: char…
Ofentse
  • 3
  • 2
0
votes
1 answer

Script is creating files for unknown reason

I wrote a script which should check if files were written in specific folders. For unknown reason, this script also creates a file in each of these folder with the name "0". Does anyone have an idea, why this is happening? sFolders=$(ls -d…
IngoH
  • 159
  • 7
0
votes
2 answers

Counting process instances with grep & wc

I am trying to count process instances using the following command: $ ps -ef | grep "test.sh" | egrep -v "grep|vi|more|pg" | wc -l 1 Which works perfectly on the command line, but in the script when I assign the output to a…
roy
  • 6,344
  • 24
  • 92
  • 174
0
votes
1 answer

Counting the number of lines in each column

Is it possible to count the number of lines in each column of a file? For example, I've been trying to use awk to separate columns on the semi-colon symbol, specify each column individually and us wc command to count any and all occurrences within…
Spr0ck3t
  • 47
  • 5
0
votes
1 answer

Command HEAD in Cygwin doesn't work

I'm a Windows sysadmin trying to setup a Cygwin in a Windows 2016 environment. Not a Linux or developer person, but I'm open to learn. I'm able to install Cygwin (x86/64) and most of the commands work just fine. But there is 2 commands that doesn't…
0
votes
1 answer

Count number of lines in each directory

I have a directory structure as below output/a/1/multipleFiles output/a/2/multipleFiles output/a/3/multipleFiles output/b/1/multipleFiles output/b/2/multipleFiles output/b/3/multipleFiles I want to know number of lines each directory…
Abhinay
  • 612
  • 1
  • 6
  • 23
0
votes
2 answers

Searching for .extension files recursively and print the number of lines in the files found?

I ran into a problem I am trying to solve but can't think about a way without doing the whole thing from the beginning. My script gets an extension and searches for every .extension file recursively, then outputs the "filename:row #:word #". I would…
user9610829