Questions tagged [wc]
`wc` utility counts newline, word, and byte for file(s) or standard input.
196 questions
4
votes
1
answer
116
views
Why does "cat | wc -c" shows different size than "ls -l" for a specific file?
The distro is Ubuntu 22.04 and I'm running a newly-created ext4 filesystem that I have copied my setup to (using rsync on a different machine). I was running a manually written (python) filesystem ...
0
votes
3
answers
84
views
Pass output of command line to awk variable
I am trying to normalise a data file using the number of lines in a previous version of the data file. After reading these questions, I thought this could work:
awk -v num=$(wc -l my_first_file.bed) '{...
0
votes
2
answers
57
views
wc to get character count of a file but exclude the initial characters of each line and the first line of the file?
I have some text files the looks something like this:
Introduction and some meta data
[00:00.000 --> 00:04.380] Lorem ipsum dolor sit amet, consectetur adipiscing elit.
[00:04.980 --> 00:07.200]...
0
votes
0
answers
57
views
Why is wc with multiple paths much faster than one by one execution?
Running wc with multiple files is an order of magnitude faster than running it file by file. For example:
> time git ls-files -z | xargs -0 wc -l > ../bach.x
real 0m2.765s
user 0m0.031s
...
0
votes
0
answers
44
views
When using 'wc \-l' to count the number of file lines, the result is less one [duplicate]
I want to count the number of file lines, so i use the command wc -l file. However, I notice that the result is incorrect which one less than the real number of lines. For example, the number of lines ...
0
votes
2
answers
146
views
Counting Files in Remote location using sftp in shell script
Getting Error with the below command to check on the Remote directory a specific type of files. The requirement is to get the count of the specific files.
file_exists=$(sftp $FTP_UNAME@$FTP_HOST ls *$...
0
votes
0
answers
50
views
How to extract the number of lines from the wc command output
When running wc -l models.txt, we get the output which looks like 2113 models_work.txt. I wonder how to get the 2113 from that output using the cut command or something along those lines. It doesn't ...
0
votes
1
answer
53
views
Moves files with the same name to a directory and writes the counted number to the directory name
find /volume1/file/* -type f \( -name "*DF*" -a -name "*LIVE*" \) -print0 | while IFS= read -d '' file
do
# extract the name of the directory to create
dirName="${file%...
6
votes
2
answers
930
views
Why does wc and stat produce different results for /proc/[pid]/cmdline?
I am trying to understand why wc and stat report different things for /proc/[pid]/cmdline.
wc says my shell's cmdline file is 6 bytes in size:
$ wc --bytes /proc/$$/cmdline
6 /proc/10425/cmdline
stat ...
0
votes
2
answers
122
views
How do I count all the files at different subfolder using for loop
I want to know could I wc -l files are in subfolder.If only one file I can use code like below.
find ./calss{1..20}/ -name 'C1.student' | xargs wc -l
In fact, I have 20 folders , every folder contain ...
0
votes
1
answer
1k
views
wc -l filename is showing one row less. Please guide
with command
wc -l filename
it is showing one row less when total number of rows inside file are 2 but it is showing 1 only. Please guide.
5
votes
2
answers
1k
views
How can I run wc on each result of the find command?
I want to see how many lines exist in each file that has been found using the find command.
I know I can use wc -l to find the lines number of a single file. But this does not work when piped from the ...
18
votes
3
answers
4k
views
How to live update `wc -l`?
I have a command <streaming ls> | wc -l, it works fine, but the <streaming ls> takes a while, which means I don't get the final line count until a few minutes later.
Is there a way to have ...
1
vote
2
answers
1k
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
2k
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 ...
0
votes
1
answer
957
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
452
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 ...
0
votes
3
answers
121
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
108
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?
0
votes
1
answer
116
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
1k
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.*/ -...
3
votes
2
answers
5k
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
220
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 ...
0
votes
2
answers
109
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&...
2
votes
3
answers
3k
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?
4
votes
2
answers
2k
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
730
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 ...
1
vote
2
answers
775
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., ...
1
vote
0
answers
70
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
387
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 ...
5
votes
5
answers
2k
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.
...
-3
votes
1
answer
89
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 ’{}’ ; | ...
0
votes
3
answers
2k
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
1k
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 ...
0
votes
2
answers
116
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....
0
votes
1
answer
442
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 ...
0
votes
1
answer
456
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 ...
2
votes
2
answers
350
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 ...
0
votes
1
answer
93
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
1k
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
2k
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
57
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 ...
2
votes
2
answers
708
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 (...
1
vote
2
answers
651
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.
...
14
votes
4
answers
39k
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 ...
0
votes
0
answers
749
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 ...
0
votes
4
answers
348
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
2k
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....
1
vote
2
answers
345
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 ...