Questions tagged [wc]

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

Filter by
Sorted by
Tagged with
2
votes
3answers
50 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
40 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
32 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
46 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
29 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
200 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
451 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
317 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
50 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
57 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
103 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
5k 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
52 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
33 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
201 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
61 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
102 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
357 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
9k 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
384 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
186 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
361 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
89 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
161 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
717 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
152 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
279 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.
0
votes
3answers
2k 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
456 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
197 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
903 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
626 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
502 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
4k 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
851 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
79 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
407 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?
2
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
508 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 ...
1
vote
1answer
86 views

Command output retention while counting lines

I was reading Count number of lines of output from previous program and found it helpful. However, while $ grep -i [pattern, file] | tee >(wc -l) gives me a nice output of the grep lines and the ...
3
votes
3answers
401 views

Listing number of files in each folder where folder name matches a pattern

I would like to recursively search a directory tree and list the number of files available in each folder that have a name corresponding to a given string. In effect, I would like to return results of:...
2
votes
1answer
389 views

Finding the Count for a String on Multiple Zipped Files in Multiple Directories (non aggregated)

I'm trying to figure out the number of lines that contain the strings "event" and "type". The files I want to search through are in multiple folders and are zipped. I'm able to get an aggregated count ...
6
votes
1answer
2k views

Finding number of lines using find command

Consider the R source code repository found at https://cloud.r-project.org/src/base/R-3/R-3.4.4.tar.gz . I unzipped the repository into a folder. Now, I wish to find out how many total lines are ...
1
vote
3answers
19k views

sort Find how many distinct values are among the certain column

For example, this is the list.txt Joe 3 Jack 1 Ulysses 6 Fox 2 Cassidy 1 Jones 6 Kevin 7 Then the output should be 5 because there are 5 different values in the 2rd column. How should I finish ...
0
votes
3answers
7k views

Use -grep to count number of 6-letter words start with 'bar' and ends with 'i' or 'n'

I want to count the number of 6-letter words that start with 'bar' and end with 'i' or 'n'. For example, given this file: barxxi barxxc barxxn barqwq barovo the output should be 2 (integer), since ...