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
4
votes
9 answers

Append wc lines to filename

Title says it all. I've managed to get just the lines with this: lines=$(wc file.txt | awk {'print $1'}); But I could use an assist appending this to the filename. Bonus points for showing me how to loop this over all the .txt files in the current…
Andrew Hall
  • 139
  • 7
4
votes
12 answers

Suppressing summary information in `wc -l` output

I use the command wc -l count number of lines in my text files (also i want to sort everything through a pipe), like this: wc -l $directory-path/*.txt | sort -rn The output includes "total" line, which is the sum of lines of all files: 10 total 5…
4
votes
2 answers

Unix: How can I count all lines containing a string in all files in a directory and see the output for each file separately

In UNIX I can do the following: grep -o 'string' myFile.txt | wc -l which will count the number of lines in myFile.txt containing the string. Or I can use : grep -o 'string' *.txt | wc -l which will count the number of lines in all .txt extension…
Ravid Goldenberg
  • 2,119
  • 4
  • 39
  • 59
4
votes
2 answers

Finding number of lines of a data file using command line

There is a conventional way to read each line one by one and check iostat hits nonzero or negative value at every reading. However, I would like to call system(command) routine and use wc -l command to count the number of and then want to allocate…
hbaromega
  • 2,317
  • 2
  • 24
  • 32
4
votes
2 answers

Whats is the behaviour of the "wc" command?

For example: myCleanVar=$( wc -l < myFile ) myDirtVar=$( wc -l myFile ) echo $myCleanVar 9 echo $myDirtVar 9 myFile why in "myCleanVar" I get an "integer" value from the "wc" command and in "myDirtVar" I get something like as: "9 file.txt"? I…
shogitai
  • 1,823
  • 1
  • 23
  • 50
4
votes
5 answers

R data.table fread command : how to read large files with irregular separators?

I have to work with a collection of 120 files of ~2 GB (525600 lines x 302 columns). The goal is to make some statistics and put the results in a clean SQLite database. Everything works fine when my script import with read.table(), but it's slow. So…
fxi
  • 607
  • 8
  • 16
4
votes
2 answers

Why wc adds plus one

Lets say I have a word of length N. word0=`echo` # N = 0 word1=`echo A` # N = 1 word2=`echo AB` # N = 2 word5=`echo ABCDE` # N = 5 word4=`echo "ABCD"` # N = 4 I use wc to get the length ofwordN, for example: echo $word0 | wc 1 echo…
pogibas
  • 27,303
  • 19
  • 84
  • 117
4
votes
2 answers

get count of the word in all files

I have a directory tree with a bunch of folders and subfolders in it and a bunch of files in those sub folders. I need to get the count of the word 'Hello' in each of those files and display the result as 'File 'a' has 'Hello' n times', 'File 'b'…
user1455116
  • 2,034
  • 4
  • 24
  • 48
3
votes
1 answer

How do I tell wc to stop reading?

I have a program that fork()s a new process and then overwrites that new process's stdin with my file descriptor pipe fd. In this process, I then use execvp() to execute wc and it should read its input from the parent. In the parent, I then write to…
chustar
  • 12,225
  • 24
  • 81
  • 119
3
votes
4 answers

How can I compare 3 files together (to see what is in common between them)?

I want to compare 3 files together to see how much of the information in the files are the same. The file format is something like this: Chr11 447 . A C 74 . DP=22;AF1=1;CI95=1,1;DP4=0,0,9,8;MQ=15;FQ=-78 GT:PL:GQ…
mahmood
  • 1,203
  • 5
  • 16
  • 27
3
votes
2 answers

What is wc -c different from ${#} when I count number of characters in Linux?

echo $SHELL /bin/bash echo $SHELL | wc -c 10 echo ${#SHELL} 9 The number of characters in $SHELL (e.g. /bin/bash) is 9, so why is the result is 10 when use wc -c?
disney82231
  • 189
  • 1
  • 3
  • 11
3
votes
1 answer

File Output From C Program Behaving Strangely When Counting Lines

I am using C to parse a large flat file and output relevant lines into an output file. The output file should be around 70,000 lines. If I open the file in gedit, it displays exactly as expected, with the correct number of lines and line lengths.…
Fred Olsen
  • 33
  • 2
3
votes
1 answer

Grep for specific text from kubernetes multiple pods

I have two pods running for a specific service. I want to get logs related to both the pods and check for specific text. For that I used ,as described here: kubectl logs -l app=my-app -c my-app-container --since=25m | grep -i "search-text" |wc…
Sachith Muhandiram
  • 2,819
  • 10
  • 45
  • 94
3
votes
1 answer

-exec wc -l {} \; prints count and path, I just need count

Lines=(find $FILEDIRECTORY -iname "*$FILEENDING" -exec wc -l {} \;) The User can put in his path and file ending and it should count how many lines each program has... if User just wc -l it prints me out how man files I have with that file ending…
user14636593
3
votes
3 answers

linux command wc output format

I need to write a perl that mimic linux command wc exactly(including and especially output format), while having realized the functionality, the output of wc is really a headache, it seems that it is changing all the time, the following are a few…
user685275
  • 2,097
  • 8
  • 26
  • 32
1 2
3
23 24