Questions tagged [wc]
`wc` utility counts newline, word, and byte for file(s) or standard input.
169
questions
1
vote
2answers
57 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
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
181 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 ...
3
votes
5answers
869 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
47 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
129 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
62 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
42 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
59 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
65 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
39 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
417 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
9answers
472 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
541 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
72 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
134 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.
...
10
votes
4answers
9k 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
102 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
383 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
2answers
115 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
165 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
392 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 ...
4
votes
4answers
12k 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
935 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
197 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
385 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
94 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
215 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....
0
votes
2answers
980 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+ ...
2
votes
3answers
216 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
361 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.
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?
2
votes
4answers
514 views
How to count the characters of jar files by wc
Under the folder /usr/hdp/2.6.4.0-91/tez_hive2/lib/
We have .jar files as the following
$ ls /usr/hdp/2.6.4.0-91/tez_hive2/lib/ | grep ".jar"
async-http-client-1.8.16.jar
azure-data-lake-store-sdk-...
0
votes
1answer
2k views
How to use wc, grep and ls to list all files that are at least 10,000,000 bytes in a directory? [duplicate]
Now I find that wc -c could show the size of file, then how to select them and list them?
It should be a single pipeline of commands.
0
votes
1answer
271 views
print number of lines and words in a single line with one spacing in shell scripting [closed]
When I am using wc -lw filename, I am getting output separated into two spaces. But I want only one space separated. How to do this?
0
votes
2answers
99 views
Save in a file first 7 file in the directory /bin that starts with c
I have write a command in the shell of linux to count the file (in total 8) starting with 'c'in the directory /bin
find /bin/[c]* -type f | wc -l
What I wish to do now, it's save the name of the ...
1
vote
4answers
1k views
Count the number of files and folders containing a certain string
Let's say I'm in the Desktop directory and want to count the number of files and directories whose name is exam. It should also count the files containing the string exam. So to sum it up I need to:
...
1
vote
1answer
845 views
run grep and wc -l in multiple files in recursive manner
I have multiple fasta files I want to count the lines starting with ">" (no quotes).
What I usually do is
grep ">" file.fasta | wc -l
This works for one file at the time. I'm trying different ...
-1
votes
3answers
646 views
Why ls | wc outputs 3 lines in dir with 3 one-line files? [closed]
$ ls
1.txt 2.txt 3.txt
$ ls | wc
3 3 18
All three files has only 1 line, but ls|wc outputs '3'.
0
votes
2answers
2k views
How to use “wc -l ” on this line? Count rows within shell script and output the count value only [closed]
#!/bin/bash
/abc/qwerty/AAAooo/testing/CBA_Car/Config/Test_Ctr.env
OUTPUT_FILE_NAME=$1
DATE=$2
cp /abc/section/AAAooo/CBACenter/slack_2010-05-1.txt ${OUTPUT_FILE_NAME}
How do I perform a count ...
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 (....
1
vote
1answer
999 views
searching letters in one line using grep and wc
I've created a text file with 1000 random uppercase and lowercase letters:
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | head -c 1000 > file1
How many times does the word 'cat' appear in this file, ...
-1
votes
2answers
87 views
analyzing ps|wc output
First - i wanted to know how many process are currently running so i used this command:
$ ps | wc
i was expecting to one number, but the output was:
20 115 844
Three numbers were printed - with ...
-1
votes
1answer
536 views
Removing files containing, only, one row? [duplicate]
I have large number of csv files saved within a folder. I would like to, only, delete the csv files that contains one row, how can I do that?
3
votes
2answers
3k views
wc -c gives me one extra character count
So I made a script that adds users to the system, and I wanted to force the length of the usernames to 8 characters or below.
#!/bin/bash
# Only works if you're root
for ((a=1;a>0;a)); do
if [[ ...
1
vote
4answers
790 views
Finding string multiple positions in a large text file
I need to find the exact positions within the text of a certain string. i.e.
File:
to be or not to be, that's the question
String "to". Output needed: 0,14 (characters from the beginning until I ...