Questions tagged [wc]

`wc` utility counts newline, word, and byte for file(s) or standard input.

Filter by
Sorted by
Tagged with
1 vote
2 answers
66 views

How to count the number of lines per file in a directory, then create summary of number of files with n lines

I'm trying to create a summary of how many files in a directory have n number of lines in them. I'm using wc -l * | sort to print out the number of lines against the name of each file. What I'm trying ...
-1 votes
1 answer
169 views

Find how many words in a file contain a number in them?

I am trying to find the total number of words in a specific file that contain a number. Not a specific number, I'm just looking for words that contain any number at all. I tried using the grep and ...
  • 1
0 votes
1 answer
99 views

Linux - count words with more than a certain length of characters

i want to know how to count the number of words in a .txt file that has more than 5 characters, using egrep and wc. Please, be clear as i'm new to linux.
0 votes
3 answers
202 views

Find number of lines between a pattern inside specific filetype

I have a notes.json file inside each directory. The following command counts length of each notes.json file and returns a sorted output by each file's number of lines. find . -name notes.json | xargs ...
  • 7
0 votes
3 answers
38 views

Sort files by LoC - sort not working when piped from wc -l

I'm trying to sort a directory of files by LoC. But sort appears to do nothing if the lines are piped in: paths=`find ./src/ | egrep "\.(cpp|h)$"` for path in $paths; do wc -l $path | sort -...
-1 votes
1 answer
63 views

How to automatically count number of lines printed by each command?

How to automatically count number of lines printed by each command? Examples: $ echo xxx xxx 1 $ ls -1 xxx yyy zzz 3 $ > t0.txt 0 etc. I.e. how to correctly add | wc -l into .bashrc?
  • 407
0 votes
1 answer
72 views

How to display a continuous wc on stdout? [duplicate]

Lets say you have this program: #!/usr/bin/env python import time while True: print("True") time.sleep(1) then you run it: ./clock.py | wc -l This will never return anything ...
2 votes
2 answers
400 views

Count number of rows of files matching pattern [closed]

I would like to list the files matching a specific pattern along with their number of rows. So far I have tried the following, which list me the files matching the desired pattern: find 2021.12.*/ -...
1 vote
2 answers
1k views

wc command with no FILE argument (reading from standard input)

Regarding wc (word count) command... I am trying to understand the following (from man wc which I have quoted below plus added a longer quote at end of my question) With no FILE, or when FILE is -, ...
-6 votes
2 answers
65 views

How do you print out repeated lines according to my problems below? [closed]

Below are the questions that I'm having trouble with, I only know how to redirect the stdout of ls to the foobar file on question 1: ls > foobar Write a command line to redirect stdout of the ...
  • 1
0 votes
2 answers
64 views

Redirect and rows count in filename

I try to name a file with rows count in a crontab : * * * * * ~/script > "~/targetfile-$(rows-count).csv" I can do : * * * * * ~/script > "~/targetfile-$(~/script | wc -l).csv&...
  • 111
0 votes
0 answers
87 views

how to record count a .csv file combining two columns

I have a requirement to capture record count for a .csv file, but here is a catch The .csv file is having total 48 columns column 1 - DATE (yyyy-mm-dd) , column 2 - TIME (Time stamp - hh24:mi:ss) ...
0 votes
3 answers
968 views

Print number of files excluding directories [duplicate]

I learned that 'ls | wc -l' command prints number of files in the current directory, but it includes all files and directories. Can I do the same task only for pure files excluding directories?
  • 149
4 votes
2 answers
378 views

Difference between wc -c and ${#}?

I've created script, where I encoded string 28 times with base64. Then I wanted to echo count of chars in outputted string. First I used ${#var} which gave me 34070. Then I tried on the same string ...
-1 votes
1 answer
347 views

Print filename, number of line with file size and modification date

I want to print the File Name, Size of file, modification date, Number of line in a file. At present I use below command to achieve my work but it's hectic to do manually everytime ls -lrth file1.csv ...
  • 3
1 vote
2 answers
213 views

$(grep -w "xyz" prog.R | wc -l) -ge 3

I am a bit new to unix and trying to figure out what the following command is doing: $(grep -w "xyz" prog.R | wc -l) -ge 3 I assume that the outcome would be boolean. The first part (i.e., ...
  • 11
1 vote
0 answers
26 views

Append rowcount for all files in a directory to filename before extension

I am trying to write a one-liner to append a row count to the filename of each file in a directory before the extension. I thought I could do this with wc -1 but I am struggling to get it in a ...
3 votes
2 answers
309 views

How do you replace sed and wc with awk? (counting names in directories)

I'd like to count the number of elements inside a folder. I thought of function lsc { /bin/ls -l $1 | sed 1d | wc -l } but then I remembered how awk people reduced those kind of pipes, getting rid of ...
  • 871
2 votes
5 answers
1k views

How to exclude the . and .. using ls or find?

I have 35 files and directory in my home at the first level (without descending into subdirectories). But the results are "faked" and report 36 because they include the . special directory. ...
  • 11.3k
-3 votes
1 answer
64 views

Basic command problems

I tried to figure out what is the difference those commands (for a school project), but for me its chrashed or running for more than 10min~ So, the sample: sudo find / -type f -exec file ’{}’ ; | ...
1 vote
3 answers
766 views

"wc -l" takes very long for my files, is there a faster alternative?

I need help in writing script that outputs the number of lines in each of a number of large files. wc -l is taking a long time, so I'm looking to use awk command to display the last line number for ...
2 votes
3 answers
579 views

Count characters in line after first grep result, but removing new line from count

The problem: I have multiple text files (.fas), which look like this: file1.fas: >species1 AICGICVIAGIAIYIAAICG >species2 AICGIVVYICAGAYICAGCG file2.fas: >species1 AIG >species2 GCI I'm ...
  • 145
0 votes
2 answers
69 views

Count the number of directories in a list of directories

I have a large number of directories, and I want to count with bash commands the number of directories in each of these directories. I am having a hard time piping ls and wc to achieve what I want. E....
  • 257
0 votes
1 answer
36 views

Piping and writing additional output to the output file

I want to write the output of wc -l to a file and before the number, I want to add the date. For example, $ wc -l file.txt 25 $ I want to append Wed Jul 8 17:30:17 +0130 2020 25 to another text ...
  • 1,049
0 votes
1 answer
236 views

Replace with lines number in specific line of a text file

What I need to do (in Bash) is a replacement of a specific characted of the second line in a text file with the number of lines in this file. So, this does the job of counting the lines: cat test.csv ...
  • 103
2 votes
2 answers
226 views

Loop through folders and count files in TARs

I need to go through folders and count files in TARs with same name. I tried this: find -name example.tar -exec tar -tf {} + | wc -l But it fails: tar: ./rajce/rajce/example.tar: Not found in ...
  • 23
0 votes
1 answer
65 views

use wc -l after succesfuly executing other commands first

from a file (/etc/services) i need to take out all services, exluding all double or more entries per service, exluding lines starting with '#', sort alfabetically and store to a file. After all this ...
0 votes
1 answer
2k views

word count redirect

I can't seem to answer this question: Use the command wc to count the number of words in the file /course/linuxgym/gutenberg/0ws0310.txt. Store the exact output of the wc command when used with the ...
6 votes
9 answers
762 views

Position, by word count, of all repetitions of a word in a text file

I want to find where a word appears in a text file — as in the number of words into the text that a word occurs — for all instances of that word, but I'm not sure even where to start. I imagine I'll ...
4 votes
4 answers
1k views

`wc -l` alternative that displays the count, as it receives the lines

I'm using wc -l to count the lines in output of a command, as the input is piped to it. commad | wc -l This works fine, but if command is doing some heavy computation, this is quite slow. Is there ...
0 votes
2 answers
54 views

Perform series of commands on every value in a field

I have a tsv file. For a specific value in a column 5, I want to extract all the rows, and then cut three columns and then count the unique lines. For example for string 'abc' in column 5, I want awk ...
  • 67
2 votes
2 answers
415 views

How to find and count matching data for an ID column in two files?

I've got two genetic datasets which have matching chromosome position IDs. I want to count how many times file 1's chromosome position IDs appear in file 2. For example my data looks like: File 1 (...
  • 217
1 vote
2 answers
391 views

diffrence between ls -l *.<sometthing> | wc -l and ls -l | grep <something> | wc -l

I have a folder with a huge file list that I want to count. I was doing ls -l *.json | wc -l and it was working fine, till the list apparently gone huge enough that this command didn't work any more. ...
11 votes
4 answers
21k views

How to skip the first line of my output? [duplicate]

Here is the issue, I would like to count the number of jobs I have in the hpc, but it is not one of the readily provided features. So I made this simple script squeue -u user_name | wc -l where ...
  • 261
0 votes
0 answers
442 views

Command "wc -l" displays wrong count of lines, possibly because each line starts with a comma?

I have a czv.gz file and when issuing "less" command it looks like this COLUMN1,COLUMN2,COLUMN3 ,value1,value2,value3 ,value4,value5,value6 ... There are thousands of lines in a file but when I ...
  • 143
0 votes
4 answers
100 views

Get file names of n files with highest line count

I am trying to get x amount of file names printed from highest line count to lowest. ATM i have this wc -l /etc/*.conf |sort -rn | head -6 | tail -5 | and i get this 543 /etc/ltrace.conf 523 /...
0 votes
2 answers
1k views

Error in wc command to read number of lines in file

I have been using wc -l to check for the number of lines exist in my files. It worked fine always but not this time. I have 120 big files that are supposed to have at least two lines in each of them....
  • 191
1 vote
2 answers
260 views

Wrong result when recursively count lines with wc

I am using the following Linux command to recursively count lines of text files in a folders structure: find . -name '*.txt' | xargs -d '\n' wc -l This outputs all found files and their number of ...
-2 votes
3 answers
411 views

How to count the number of occurrences of all strings in the file while getting the average of each string

I am trying to count the number of occurrences without specifying a specific string, just using the output of the cut command to print the number of each repeated string using grep. I then want to get ...
  • 13
4 votes
2 answers
446 views

Is there a way to count the number of lines of text in a file including non-delimited ones?

The POSIX wc command counts how many POSIX lines in a file. The POSIX standard defines a line as a text string with the suffix \n. Without \n, a pure text string can't be called a line. But to me, ...
1 vote
0 answers
58 views

How to get no of lines and the data of the file created data in unix

I have a file named as abc.txt and I am trying to extract no of records present in the file and the file creation date. wc -l abc.txt This is giving me only no of records in the file. How to get ...
5 votes
4 answers
19k views

count number of files in directory with a certain name

I found this code here https://www.tldp.org/HOWTO/Bash-Prompt-HOWTO/x700.html which nicely gives me the number of files in my directory. ls -1 | wc -l but I only want to know how many of those files'...
  • 223
2 votes
3 answers
4k views

wc -l to count lines all txt files in folders and subfolders

I have a few hundred txt files in several subfolders and I would like the count the lines in each txt file. I can do this for all txt files in the current directory by using: for f in *.txt; do wc -l ...
  • 207
3 votes
3 answers
219 views

Repairing the headers of phylip bioinformatics files to accurately reflect the updated number of samples in the file(s)

I have a dataset that I am working with made up of phylip files that I have been editing. Phylip format is a bioinformatics format that contains as a header the number of samples and the sequence ...
1 vote
1 answer
436 views

Automatically print number of lines of command line output

In my fish shell, I am using fish command timer to automatically show the duration of each command after it has been executed. This is a neat feature, which I recommend. Now I want something similar ...
0 votes
1 answer
101 views

wc behaves differently on Unix and Linux

I observed different results when I tried echoing value and counting the number of characters with "wc -c" on Linux and SunOS(Unix). root@SunOS-machine:~# echo "1" | wc -c 2 root@Linux-machine:...
  • 193
0 votes
1 answer
504 views

Does the wc command strip the trailing line feed from txt files?

I'm currently building a replica of the wc command line call (in C). I have a file [tst.txt] and the C code to read that file. The wc tst.txt command responds with the output: 2 6 20 tst....
  • 1
0 votes
2 answers
2k views

Remove new line, space from file

I have many files in a directory each like so: AAA AA AAAAAA A AAAA I want to end up with this: AAAAAAAAAAAAAAAA So that when I run: find ./ -name '*' -exec wc -m {} + I get back 16, not 20+ ...
  • 1
2 votes
3 answers
673 views

Determine the number of directories inside a tar file without extracting it

I need to count directories inside an archive file (e.g. tar.bz) without extracting the archive. Note that the archive is too big so that it will be hard to extract then count directories using ls | ...
  • 171
3 votes
1 answer
805 views

Why does echo "a" | wc -m return 2? [duplicate]

Why does echo "a" | wc -m echo 2? Other variations in which I try to reduce the number of spaces yield the same result.
  • 239