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

"Argument list too long" error when passing a find output as arguments

I have some 5 million text files under a directory - all of the same format (nothing special, just plain text files with some integers in each line). I would like to compute the maximum and minimum line count amongst all these files, along with its…
JasonB
  • 555
  • 2
  • 7
  • 13
2
votes
1 answer

Why is `tail -n 1` returning two lines on this file when I would expect 1

The file in this gist has two long lines. When I run tail -n 1 on it, both lines are returned (I would expect just the last one). When I run head -n 1 on it, only the first line is returned (as expected). When I run wc -l on it, it returns 1 (I…
nbrustein
  • 727
  • 5
  • 16
2
votes
3 answers

UNIX wc -l with line length restriction

I need to count the number of lines in a file, in a UNIX shell script, but I need the number of lines under 80 characters, and if there are more than 80 characters, count it as multiple lines. I know wc -l counts the number of lines, and I know…
skeggse
  • 6,103
  • 11
  • 57
  • 81
2
votes
2 answers

Real bash line count

I'm parsing a temp file whose lines would like removed so I run: tr '\n' ' ' < temp > temp2. Now when I wc -l temp2 it is returning 0 lines instead of 1 which was unexpected for me. After checking the manual, wc -l counts just the newlines and not…
2
votes
6 answers

Search file for usernames, and sort number of instances for each user in file?

I am tasked with taking a file that has line entries that include string username=xxxx: $ cat file.txt Yadayada username=jdoe blablabla Yadayada username=jdoe blablabla Yadayada username=jdoe blablabla Yadayada username=dsmith blablabla Yadayada…
2
votes
1 answer

Counting symbols without spaces in bash

I want to create script which will count symbols from string "word blah-blah word one more time word again". It will count symbols before "word" only and every "word" should be written to new string. So output of script should looks like that: word…
Nick
  • 55
  • 1
  • 10
2
votes
1 answer

Regarding the Unix command "wc" what is considered as a word?

The command wc provides lineCount, wordCount, and charCount. I am writing a program that simulates the wc command as it takes a file and spits out the 3 properties. Line count is easy because if it sees \n it will ++lineCount and if a char exists…
maritaslag
  • 23
  • 1
  • 5
2
votes
1 answer

vim and wc give different line counts

I have two csv files that give different results when I use wc -l (gives 65 lines for the first, 66 for the second) and when I use vim file.csv and then :$ to go to the bottom of the file (66 lines for both). I have tried viewing newline characters…
p-robot
  • 4,652
  • 2
  • 29
  • 38
2
votes
9 answers

What is the shortest one-liner to divide the line count of one file by another in bash?

In a bash shell, I am trying to write a short one-liner to divide the line count of one file by the line count of another. I would like show at least two decimal places from floating-point division. In other words, I would like a one-liner to print…
Jake Sebright
  • 799
  • 8
  • 16
2
votes
1 answer

wc does not return an integer value - integer expression expected

I am trying to run this script: #!/bin/sh cd $1 for i in */*.$2 do if [ 'wc –c $i' -gt $3 ] then chmod o-r $i fi done When I run the script: ./script folder1 txt 500 I get this error: ./script: line 5: [: wc –c $i: integer…
Marcin Kulik
  • 845
  • 1
  • 12
  • 28
2
votes
2 answers

error when using wc -c with file names

I am running this code, that sorts files in the desired folders. If a file name has 13 chars it should run the first statement, else the second. for i in *.png; do if [ "$($i | wc -c)" -eq 13 ]; then echo cp $i…
sanjihan
  • 5,592
  • 11
  • 54
  • 119
2
votes
2 answers

how to count the number of lines in a text file that start with a date

I have a file that has the content as 2004-10-07 cva create file ... 2003-11-11 cva create version ... 2003-11-11 cva create version ... 2003-11-11 cva create branch ... now I want to count the number of…
noob_coder
  • 749
  • 4
  • 15
  • 35
2
votes
3 answers

Bash counting letters in string, output always a little different

I have a little problem with my script. My program receives a string from the user and adds it together to make one large string in a loop that will only end if user types asterisk (*) somewhere in the code. Later on that code counts letters,…
jakubek278
  • 41
  • 1
  • 2
  • 8
2
votes
2 answers

How do I find the number of all .txt files in a directory and all sub directories using specifically the find command and the wc command?

So far I have this: find -name ".txt" I'm not quite sure how to use wc to find out the exact number of files. When using the command above, all the .txt files show up, but I need the exact number of files with the .txt extension. Please don't…
2
votes
4 answers

Output of wc -l without file-extension

I've got the following line: wc -l ./*.txt | sort -rn i want to cut the file extension. So with this code i've got the output: number filename.txt for all my .txt-files in the .-directory. But I want the output without the file-extension, like…