Questions tagged [wc]

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

Filter by
Sorted by
Tagged with
1
vote
2answers
78 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
2k 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
35 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
30 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
0answers
36 views

Different number of lines when using “cat -n [file]” and “wc -l [file]” [duplicate]

I'm following this text about another Linux command not related to my question. So I have file1.txt with the following content: geek for geeks If I use cat -n file1.txt I have the following as ...
0
votes
2answers
89 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
40 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
72 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
332 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
48 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
4k 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
69 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
173 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
193 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
80 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
108 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
339 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
84 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 | ...
2
votes
1answer
150 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
497 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
381 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
114 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
45 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
582 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: ...
0
votes
1answer
337 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
335 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
952 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
2k 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
595 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
67 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
179 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
2k 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
189 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
67 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
336 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
180 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
11k 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
6k 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 ...
11
votes
2answers
3k views

Why does wc <<<“$string” show a one-byte-longer length than printf “$string” | wc?

Accidentially, I found out that wc counts differently depending on how it gets the input from bash: $ s='hello' $ wc -m <<<"$s" 6 $ wc -c <<<"$s" 6 $ printf '%s' "$s" | wc -m 5 $ ...
1
vote
2answers
594 views

Given two files, how do I find the total number of line changes?

I tried using this command to compute number of lines changed between two files: diff -U 0 file1 file2 | grep ^@ | wc -l My problem with this command is that if one file has only one line, and the ...
0
votes
1answer
29 views

How to find how many paragraphs in a file?

For example 1006.2100 49.2000 1015.6100 47.7000 1023.1100 25.2000 1024.2200 33.3000 1025.5100 26.3000 1040.6100 29.0000 1151.57 3 169.1900 31.5000 174.9900 31.5000 193.1000 19.1000 196.4500 17.9000 ...
11
votes
8answers
6k views

Count the number of blank lines at the end of file

I have a file with blank lines at the end of the file. Can I use grep to count the number of blank lines at the end of the file with the file name being passed as variable in the script?
2
votes
1answer
1k views

Print out variables from subshell to parent shell [duplicate]

Very new to Bash and pretty confused about local/global variables/subshells. I'm not sure why the modified variables won't print out at the end of the function—I'm trying to print out a final line ...
1
vote
3answers
9k views

Counting the characters of each line with wc

Is it possible to use wc to count the chars of each line instead of the total amount of chars? e.g. echo -e foo\\nbar\\nbazz | grep -i ba returns: bar bazz So why doesn't echo -e foo\\nbar\\...
2
votes
2answers
107 views

How to get the results of ls piped to wc when running inside of a for loop?

So I am trying to make this a single command instead of having to dump the data to a file and then cat the file and pipe the output to wc -l. The whole line of code looks like this: for file in `...
1
vote
2answers
1k views

Counting files, directories, etc. in given directory and formatting output on screen

Just started a scripting class and could use some help. I am writing a script to inspect the file names of every file and directory in a given directory and accumulate a count of Every file, ...
1
vote
4answers
4k views

Count number of directories

I need a script or command that prints a number of directories which name begins from "lib" in whole directory subtree. I was trying to do it using find, grep, and wc but can't scan all directories. ...
0
votes
1answer
3k views

grep for a string in multiple files under tar and print wc -l

I am looking for a command / script that can search for the given string in multiple files under a given tar.gz file and give the wc -l of the string along with specific file name. I tried the below ...