Questions tagged [wc]
`wc` utility counts newline, word, and byte for file(s) or standard input.
172
questions
0
votes
3answers
2k views
Count occurrences of line in multiple files
I have log files that I need to grep and count the number of occurrences of a specific line.
Issue is that I must start at a specific line of the first file and only count occurrences after that line....
0
votes
3answers
35 views
Print number of files excluding directories
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
2answers
174 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
1answer
61 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
2answers
61 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
2answers
1k views
How to print few lines from middle of a file using unix shell commands? [closed]
My file contains the following lines,
$BQ
{ VOL @home }
database daba
relation tcdeatid
opendb
clear
.lruno := 72 <-- (This line lruno. := 72 has 10 times in my ...
1
vote
0answers
18 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
2answers
183 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
3answers
28k views
Run wc and display only the word count
I have been trying to create a file called ~/dictwords.txt, which contains the number of words found in the file /usr/share/dict/words.
I already created the file then I removed it because I did it ...
3
votes
5answers
881 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
1answer
49 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
3answers
156 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
3answers
71 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
2answers
43 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
1answer
26 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
1answer
71 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
2answers
76 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
1answer
44 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
1answer
532 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 ...
36
votes
6answers
27k views
List files sorted by the number of lines they contain
How can I list the number of lines in the files in /group/book/four/word, sorted by the number of lines they contain?
ls -l command lists them down but does not sort them
6
votes
9answers
479 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 ...
2
votes
4answers
620 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
2answers
51 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
2answers
87 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
2answers
146 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.
...
2
votes
3answers
3k 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 there are in that file.
How may I do this quickly and efficiently?
10
votes
4answers
10k 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
0answers
123 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
4answers
36 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
2answers
455 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....
4
votes
1answer
2k views
Send random data over TCP for a while, and count how many bytes were sent
To test data throughput, I want to 1) for X seconds 2) send random data 3) over TCP, and 4) to know afterwards exactly how many bytes were transmitted.
My best attempt (which is not much)
1) timeout ...
1
vote
2answers
140 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
3answers
174 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 ...
4
votes
2answers
395 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
0answers
53 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 ...
0
votes
2answers
6k views
How to get counts of the files present in remote directory using sftp command
I have a sftp server (Dbprd@101.102.130.23). I am trying to connect to it and search for files that contain .txt in (/files/base/incomming) path and get the count of lines in each file that contains (....
4
votes
4answers
13k 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'...
2
votes
3answers
1k 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 ...
3
votes
3answers
201 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
1answer
387 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
1answer
95 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:...
0
votes
1answer
231 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....
25
votes
17answers
6k views
How to find line with least characters
I am writing a shell script, using any general UNIX commands. I have to retrieve the line that has the least characters (whitespace included). There can be up to around 20 lines.
I know I can use ...
1
vote
3answers
8k views
Combined Word Count for Files in Directories
Is it possible to return a combined word count with wc only for certain files (like .txt files, for example) in a series of directories?
0
votes
2answers
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+ ...
5
votes
2answers
9k views
Why does wc -l tell me that this non-empty file has 0 lines?
xclip/xsel are utilities that allow you to pipe clipboard output to the shell on Ubuntu. Unfortunately, they seem to fail in combination with the wc command.
Try this. Open a new file and type:
...
2
votes
3answers
249 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 | ...
3
votes
1answer
401 views
'wc -m' shows one character too many
I am writing a program on using wc -m/wc -c to count the amount of letters in a string. It counts the letters, but adds one extra. This is what I currently have:
echo "enter a word"
read var1
echo $...
3
votes
1answer
390 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.
1
vote
2answers
462 views
wc -l command issues in SunOs to Linux migration
We are migrating from SunOS to Linux. I'm facing some problem with wc -l command. When I used wc -l <file_name>, SunOS is giving leading spaces before count where as Linux there are no leading ...