Questions tagged [wc]

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

Filter by
Sorted by
Tagged with
-1
votes
1answer
407 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|...
2
votes
4answers
543 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-...
1
vote
1answer
298 views

Count ONLY alphanumeric words in a specific column of a file

I'm given a test file and am supposed to be able to count the words in a specific column of a file. The catch is that there are some lines that contain only numbers. I know that the wc will give the ...
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
358 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?
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: ...
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
1answer
963 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 ...
-6
votes
1answer
303 views

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

I would like to create a new .wc command.
-1
votes
3answers
719 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 ...
1
vote
1answer
1k 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
94 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
600 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?
4
votes
4answers
4k views

Extra space with counted line number?

I count the number of lines of my file with this command on OSX: nl=$(wc -l < ~/myfile.txt) Say, nl turns out to be 100. Now, I wish to use the result nl in another command, but weirdly, echo 1-$...
4
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
2answers
2k 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
2answers
14k views

trying to use wc(word count) inside of a script to count the words, chars, lines of a file

i am trying to write a shell script for my OS course. but i can not get it to read the contents of a file. only seems to read what i enter in response to the question. not sure what i am missing (...
1
vote
4answers
970 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
102 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
446 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
568 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
25k 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 ...
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
1k 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 ...
2
votes
1answer
2k 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
1answer
49 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
8k 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?
5
votes
3answers
16k 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
231 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 `...
3
votes
1answer
4k views

Return count of matches with find/replace using sed

I'm trying to get a count of the number of replaced strings with find and sed. What I'm starting with: # find . -name \*.php -exec sed -i -e "s|finddddd|replaceeeee|g" {} \; This replaces four ...
1
vote
4answers
5k 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
4k 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 ...
1
vote
2answers
934 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
1k views

unix: get characters 10 to 80 in a file

I have a file containing line-separated text: GCAACACGGTGGGAGCACGTCAACAAGGAGTAATTCTTCAAGACCGTTCCAAAAACAGCATGCAAGAGCG GTCGAGCCTAGTCCATCAGCAAATGCCGTTTCCAGCAATGCAAAGAGAACGGGAAGGTATCAGTTCACCG ...
0
votes
1answer
131 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
vote
2answers
1k 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 ...
26
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 ...
8
votes
5answers
11k views

Get the number of spaces characters in a string?

How can I check how many white spaces (' ', \t) there are in the first line of a file?
2
votes
2answers
6k 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 -...
0
votes
1answer
90 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 ...
1
vote
1answer
123 views

jobs / wc: getting weird return values

I can't make sense of these return values. When I run jobs -s | wc -l, I get different results depending on what directory I'm in. If I'm in the directory that I returned to after suspending the job,...
6
votes
3answers
7k 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 ...
4
votes
1answer
2k views

wc -l not returning correct value

I have a .txt file that has 10781 lines in it. When I run wc -l on the file I get a return of 10780. If I add a blank line at the end of the .txt I get the correct result of 10781. Can someone ...
-1
votes
1answer
1k views

how to find text within a file using grep it hangs in terminal [closed]

I/m just playing around trying to hone my grep and pipe with other functions/commands. when I run grep to find a hash tag pipe it to get a count on it. The whole thing gets stuck in term like it is ...
19
votes
5answers
90k views

how to count total number of words in a file?

I am looking for a command to count number of all words in a file. For instance if a file is like this, today is a good day then it should print 5, since there are 5 words there.
8
votes
3answers
8k views

Get correct number of lines in diff output

I want to get the correct number of lines in the output of diff(specifically with -y and --suppress-common-lines options). Using a simple wc -l does not work, because if both files end without a ...
2
votes
1answer
1k views

line(records) Count and grep together in a one command on a dat file

I want to do a line count and get the number into a variable in a shell script. For eg. wc -l filename.dat gives 221 filename.dat I want to grep '221' into a variable, which I could use later. Can ...