Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [wc]

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

3
votes
3answers
117 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
45 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
71 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
47 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
57 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
59 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
57 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
2answers
67 views

Is there a quickest way to count lines in file which is of 4TB in linux?

Actually I have 4 TB of Txt file as Exported from Teradata records and I want to know How many records are there in that file.
2
votes
4answers
324 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
982 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
60 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
25 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
248 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
119 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
176 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
159 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 ...
1
vote
2answers
745 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 the below sftp server and search for the files which contains .txt in (/files/base/incomming) path and get the count of lines in ...
1
vote
1answer
276 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
44 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
56 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?
1
vote
2answers
658 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
48 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
47 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
192 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
89 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
1k 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
4k 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
4k 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
2k 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
359 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
27 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?
1
vote
1answer
738 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 ...
0
votes
3answers
5k 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\\...
3
votes
2answers
79 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, ...
0
votes
4answers
2k 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
2k 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 ...
0
votes
2answers
507 views

sed count lines between pattern - multiple files

I have multiple .txt files in one directory. Each file has a section: DONE item 1 item 2 item 3 DONE I would like to count the number of lines between the two DONE markers for each file seperately. ...
4
votes
6answers
930 views

unix: get characters 10 to 80 in a file

I have a file containing line-separated text: GCAACACGGTGGGAGCACGTCAACAAGGAGTAATTCTTCAAGACCGTTCCAAAAACAGCATGCAAGAGCG GTCGAGCCTAGTCCATCAGCAAATGCCGTTTCCAGCAATGCAAAGAGAACGGGAAGGTATCAGTTCACCG ...
1
vote
3answers
4k 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
1answer
111 views

Linux - how to get count of line in file [duplicate]

Can you tell me how to get the line count in a script? PID_COUNT = 'cat /david/file1/test.sh | wc -l ' is not working, shows an error "illegal -l".
-1
votes
1answer
261 views

Solaris 9 - Word Count (wc) command gives wrong output with 'grep -v and ps' [duplicate]

When i use 'ps', 'egrep' and 'wc' command to count number of processes, it gives me wrong value. I am running the command in 'Solaris 9' machine. MyServer $ ps -fu root | egrep -v 'bash|ksh|ssh|ef|...
24
votes
3answers
1k views

Byte count of “ls -l <random file>” versus that of “wc -c <random file>”

Is there any possible situation when ls -l file.txt is showing not the same number of bytes as wc -c file.txt In one script I found comparison of those two values. What could be the reason of ...
1
vote
2answers
708 views

Why does wc get wrong result with output from ps

To output all lines into a file /tmp/ps.txt $ ps -e >/tmp/ps.txt To count it with wc -l $ wc -l /tmp/ps.txt 172 To count it without exporting a file. $ ps -e | wc -l 173 Why ps -e | wc -l ...
2
votes
2answers
3k views

Counting number of lines in file regardless of line ending char

Suppose I'm given a variety of files, some with line endings of \r, \n and \r\n. How would I efficiently count the number of lines in a file when I don't know what to expect beforehand? Obviously wc -...
1
vote
1answer
548 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 ...
0
votes
1answer
54 views

How to create variable from piped data

The command I using is: ls -l . | totLines=$(wc -l) echo $totLines . My goal is display the total number of lines, but by assigning the output of wc -l a variable name, then displaying that variable's ...
6
votes
3answers
2k views

How to get the number of bytes in just one line of a file?

I am wondering how I can get the number of bytes in just one line of a file. I know I can use wc -l to get the number of lines in a file, and wc -c to get the total number of bytes in a file. What I ...
-6
votes
1answer
237 views

How to create new script , role like wc [closed]

I would like to create a new .wc command.