2022 Developer Survey is open! Take survey.

Questions tagged [wc]

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

Filter by
Sorted by
Tagged with
-1 votes
1 answer
52 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 ...
user avatar
  • 1
0 votes
1 answer
37 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.
user avatar
0 votes
3 answers
154 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 ...
user avatar
  • 7
0 votes
3 answers
26 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 -...
user avatar
-1 votes
1 answer
58 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?
user avatar
  • 355
0 votes
1 answer
54 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 ...
user avatar
2 votes
2 answers
161 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.*/ -...
user avatar
0 votes
2 answers
496 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 -, ...
user avatar
-6 votes
2 answers
61 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 ...
user avatar
  • 1
0 votes
2 answers
43 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&...
user avatar
  • 111
0 votes
0 answers
75 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) ...
user avatar
0 votes
3 answers
626 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?
user avatar
  • 139
4 votes
2 answers
300 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 ...
user avatar
-1 votes
1 answer
119 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 ...
user avatar
  • 3
1 vote
2 answers
135 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., ...
user avatar
  • 11
1 vote
0 answers
23 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 ...
user avatar
3 votes
2 answers
263 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 ...
user avatar
  • 862
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. ...
user avatar
  • 11k
-3 votes
1 answer
54 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 ’{}’ ; | ...
user avatar
1 vote
3 answers
554 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 ...
user avatar
2 votes
3 answers
301 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 ...
user avatar
  • 145
0 votes
2 answers
57 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....
user avatar
  • 247
0 votes
1 answer
29 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 ...
user avatar
  • 995
0 votes
1 answer
177 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 ...
user avatar
  • 103
2 votes
2 answers
184 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 ...
user avatar
  • 23
0 votes
1 answer
61 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 ...
user avatar
0 votes
1 answer
1k 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 ...
user avatar
6 votes
9 answers
637 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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 67
2 votes
2 answers
318 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 (...
user avatar
  • 217
1 vote
2 answers
335 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. ...
user avatar
10 votes
4 answers
18k 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 ...
user avatar
  • 251
0 votes
0 answers
385 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 ...
user avatar
  • 143
0 votes
4 answers
52 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 /...
user avatar
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....
user avatar
  • 177
1 vote
2 answers
215 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 ...
user avatar
-2 votes
3 answers
383 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 ...
user avatar
  • 13
4 votes
2 answers
434 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, ...
user avatar
1 vote
0 answers
56 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 ...
user avatar
5 votes
4 answers
18k 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'...
user avatar
  • 223
2 votes
3 answers
3k 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 ...
user avatar
  • 207
3 votes
3 answers
212 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 ...
user avatar
1 vote
1 answer
424 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 ...
user avatar
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:...
user avatar
  • 193
0 votes
1 answer
433 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....
user avatar
  • 1
0 votes
2 answers
1k 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+ ...
user avatar
  • 1
2 votes
3 answers
539 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 | ...
user avatar
  • 171
3 votes
1 answer
639 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.
user avatar
  • 239
4 votes
5 answers
6k views

What is a quick way to count lines in a 4TB file?

I have a 4TB big text file Exported from Teradata records, and I want to know how many records (= lines in my case) there are in that file. How may I do this quickly and efficiently?
user avatar