Questions tagged [wc]

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

Filter by
Sorted by
Tagged with
0 votes
2 answers
40 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 *$...
MALABIKA GARAI's user avatar
0 votes
0 answers
39 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 ...
Tung's user avatar
  • 171
0 votes
1 answer
50 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%...
anisphia's user avatar
6 votes
2 answers
837 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 ...
Shane Bishop's user avatar
0 votes
2 answers
107 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 ...
Roq's user avatar
  • 15
0 votes
1 answer
595 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.
user555948's user avatar
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 ...
Saeed Neamati's user avatar
19 votes
3 answers
3k 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 ...
Foobar's user avatar
  • 283
1 vote
2 answers
927 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 ...
Doodling's user avatar
-1 votes
1 answer
1k 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 ...
Doug's user avatar
  • 1
0 votes
1 answer
680 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.
LearningLinux's user avatar
0 votes
3 answers
374 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 ...
SKPS's user avatar
  • 13
0 votes
3 answers
107 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 -...
Jonathan Levin's user avatar
-1 votes
1 answer
94 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?
pmor's user avatar
  • 579
0 votes
1 answer
110 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 ...
BigBoy1337's user avatar
2 votes
2 answers
938 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.*/ -...
JejeBelfort's user avatar
2 votes
2 answers
4k 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 -, ...
PurpleMongrel's user avatar
-6 votes
2 answers
140 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 ...
Kudoss's user avatar
  • 1
0 votes
2 answers
105 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&...
JCH77's user avatar
  • 111
1 vote
3 answers
2k 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?
user67275's user avatar
  • 223
4 votes
2 answers
1k 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 ...
unnamedrider1337's user avatar
-1 votes
1 answer
679 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 ...
Satya's user avatar
  • 13
1 vote
2 answers
684 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., ...
Bishal's user avatar
  • 11
1 vote
0 answers
59 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 ...
kadagreatish's user avatar
3 votes
2 answers
371 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 ...
ychaouche's user avatar
  • 998
4 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. ...
elbarna's user avatar
  • 12.6k
-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 ’{}’ ; | ...
user439978's user avatar
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 ...
Rekha Mallam's user avatar
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 ...
Biomage's user avatar
  • 145
0 votes
2 answers
109 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....
GZ-'s user avatar
  • 317
0 votes
1 answer
385 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 ...
mahmood's user avatar
  • 1,191
0 votes
1 answer
368 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 ...
WojtusJ's user avatar
  • 103
2 votes
2 answers
321 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 ...
Rajce's user avatar
  • 23
0 votes
1 answer
86 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 ...
Dave Bulcke's user avatar
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 ...
william's user avatar
6 votes
9 answers
956 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 ...
Johnny Rollerfeet's user avatar
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 ...
Peeyush Kushwaha's user avatar
0 votes
2 answers
55 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 ...
Arsala's user avatar
  • 67
2 votes
2 answers
635 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 (...
DN1's user avatar
  • 227
1 vote
2 answers
600 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. ...
elmodeer's user avatar
13 votes
4 answers
32k 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 ...
zyy's user avatar
  • 291
0 votes
0 answers
689 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 ...
kamokoba's user avatar
  • 163
0 votes
4 answers
311 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 /...
RytisAndrulionis's user avatar
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....
web's user avatar
  • 193
1 vote
2 answers
329 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 ...
Nikola Obreshkov's user avatar
-2 votes
3 answers
538 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 ...
fgdark's user avatar
  • 23
4 votes
2 answers
496 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, ...
Just a learner's user avatar
1 vote
0 answers
66 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 ...
Rak kundra's user avatar
5 votes
4 answers
24k 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'...
Jellyse's user avatar
  • 223
2 votes
3 answers
6k 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 ...
SciGuy's user avatar
  • 207