Questions tagged [wc]
`wc` utility counts newline, word, and byte for file(s) or standard input.
197 questions
2
votes
1
answer
147
views
grep -c gives a different count to grep | wc -l
I expected these two commands to give the same count of how many lines in my file contain a letter:
grep -c '[A-Z,a-z]' archive_for_TO.050225
11873
grep '[A-Z,a-z]' archive_for_TO.050225 | wc -l
11859
...
4
votes
1
answer
150
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
131
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
77
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
93
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
66
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
237
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
78
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
70
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
1k
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
155
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
2k
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 ...