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

learn more… | top users | synonyms

2
votes
4answers
620 views

The wc -w command outputs incorrect answer [duplicate]

I have to find how many times the word shell is used in a file. I used grep "shell" test.txt | wc -w in order to count how many times that word has been used, but the result comes out 4 instead of 3. ...
1
vote
1answer
16 views

jobs / wc: getting wierd 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 ...
1
vote
5answers
108 views

How can I 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? Thanks
2
votes
5answers
145 views

List (or move) only files with a certain number of lines?

Dealing with a whole bunch of two-line config files, I'd like a way to exclude any files that have a different number of lines. So, something like: mv * destdir only if file contains exactly two ...
3
votes
3answers
149 views

Recursively print file length

How to print the length of all *.txt files in a directory? Eg: Directory content: FileA.txt FileB.txt FileC.txt FileA.csv *.txt length: less FileA.txt | wc -l 43 less FileB.txt | wc -l 13 ...
0
votes
0answers
11 views

List extensions of files and their amount [duplicate]

I want to list file extensions and the number of files for this extensions at once. I tried this: ls -R | grep -Eo "\..+" | sort -u|wc -l but it only count the number of file extensions, without wc -l ...
1
vote
4answers
75 views

How to get the number of each punctuation mark from a file

grep '[".?!"]' Returns the lines that have one of these but I have no clue how to tell how many are in each line, let alone how many ., ?, and ! there are.
-1
votes
1answer
97 views

What does ls -l | wc do?

I cannot figure out what this command does. It produces 3 numbers in my terminal but with no explanation of what those numbers are. I understand ls -l lists all files in log list format and wc is word ...
1
vote
3answers
98 views

using grep and wc commands to solve a problem

I am trying to figure out how to count the number of lines in file.txt that have at least ONE number or digit. So far I figure will count the amount of lines: wc -l filename.txt I then figure this ...
0
votes
4answers
78 views

Append the result of word count to the end of a file

I want to count the number of lines in example.txt and append the result to the end of this file. How can I do this? I tried: wc -l > example.txt
2
votes
1answer
63 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 ...
1
vote
2answers
54 views

Select file based on number of lines and manipulate the result

I have a large number of files, all with the same format. line 1: Gene ID line 2: chromosomal position line 3 - x: names of genetic variants) I want to select only files containing at least 5 ...
0
votes
1answer
49 views

Big XML - copy data from nth Occurrences to another file

<XML> <Employee> <firstname></firstname><lastname></lastname> </Employee> <Employee> ...
0
votes
1answer
37 views

wc showing differences

I have 2 directories as below /appl/exe/04/dat>ls -alrt total 290 drwxrwxr-x 30 exceed exceed 1024 Jun 11 09:04 .. drwxrwxrwx 2 exceed exceed 138240 Aug 17 03:56 . ...
0
votes
2answers
196 views

How to count the number of words of each sentences in a file using shell command?

I have text files like this: Mr.P.K.Baneerjee has visited the site today at 4.30pm The permit tag has been set in the ds busbar Opearation has been performed in presence of control engineer Opeation ...
1
vote
1answer
54 views

Recursively count occurrences of a word in identically named files in different directories

I've got several different directories that contain different versions of some files. I want to count a symbol in all versions of the same file. Here is an example of the hierarchy. directory ...
3
votes
2answers
152 views

How can I count the number of whitespace characters in a file?

I wanted to count the number of whitespace characters in a file. The best I could come up with was: tr -cd [:space:] < my_file | wc Is there a neater way?
8
votes
7answers
863 views

How to efficiently split up a large text file wihout splitting multiline records?

I have a big text file (~50Gb when gz'ed). The file contains 4*N lines or N records; that is every record consists of 4 lines. I would like to split this file into 4 smaller files each sized roughly ...
1
vote
2answers
88 views

How to print few lines from middle of a file using unix shell commands? [closed]

My file containing the following lines, $BQ { VOL @home } database daba relation tcdeatid opendb clear .lruno := 72 <-- (This line lruno. := 72 has 10 times ...
19
votes
15answers
1k views

How to find line with least characters

I am writing a shell script, using any general UNIX commands. I have to retrieve the line that has the least characters (whitespace included). There can be up to around 20 lines. I know I can use ...
2
votes
2answers
106 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 ...
3
votes
1answer
127 views

wc command issue

I have only one row in my file. When I execute wc -c file1.txt the result is 200, while the output of wc -L file1.txt is 198. What explains the difference of 2?
0
votes
1answer
53 views

`ls / | wc -l` tells more lines than `ls /` shows [duplicate]

ls / outputs two lines. $ ls / bin cdrom etc initrd.img lib lost+found mnt proc run share sys usr vmlinuz boot dev home initrd.img.old lib64 media opt root sbin ...
2
votes
2answers
96 views

grep with count of individual patterns

I have a file with MAC addresses (1/line with : as separator, sorted) and I need to find out how many times each of these MAC addresses appears in the file. I modified this: How to count occurrences ...
0
votes
2answers
99 views

A batch that cout the number of occurrences

I've to extract the number of words using each letter of the alphabet from A to Z. The script that i've to create create take as parameter the name of the dictionary file to analyze and will be used ...
3
votes
4answers
372 views

get file size and line count at the same time

I'm looking for a way to list all files in a directory, with both their size, and a line count. Right now I'm using stat -c \"%s %n\" /directory/* to get file names and sizes, and I know I can use ...
-1
votes
2answers
349 views

trying to reproduce “Unknown test operator” on HP-UX

HP-UX **** B.11.31 U ia64 ***** unlimited-user license LINE_COUNT=`wc -l ${LOG_DIR}/file_transaction.log` if [ ${LINE_COUNT:-"0"} -ge 10000 ] then mv ${LOG_DIR}/file_transaction.log ...
2
votes
2answers
160 views

How to append word count of file to file without adding the total

I am running a bash script where I am appending the line count of the arguments, which are files, to another file. It does it correctly, but I keep getting a line that says "total X", X being the sum ...
1
vote
2answers
33 views

Count and list down + advanced features

I have a few questions: I have listed the number of lines in the files in /group/book/four/word, sorted by the number of lines they contain using $ wc -l /group/book/four/word/*|sort -n ...and ...
4
votes
3answers
443 views

Copy a specific percentage of each file in a directory to a new file

For example, we have N files (file1, file2, file3 ...) We need first 20% of them, the result directory should be like (file1_20, file2_20, file3_20 ...). I was thinking use wc to get the lines of ...
3
votes
2answers
71 views

I want to reboot the system once a search had been done to see that no-one is logged in

I'm working on a user menu so that when a user logs in all they get is this menu; on this menu is a selection of reboot option. I want one of the options to be reboot the system if no one is logged ...
3
votes
1answer
360 views

Split input file into X parts of size total lines / X

Currently, my bash script splits by number of lines. However, I'd like to split a file into X pieces, each of those having total lines equal to the file length divided by X. The script is run as ...
2
votes
1answer
738 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 ...
3
votes
5answers
666 views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
1
vote
1answer
82 views

wc -m command in raspberry pi adding an extra number

I am writing a program on the pi using wc -m command to count the amount of letters in a string, however, it counts the letters but adds one extra. This is what I currently have. echo "enter a word" ...
4
votes
3answers
418 views

Time required to do pipe output to head/tail [duplicate]

There are lots of txt files in a directory. If I do time wc -l *.txt | head it takes real 0m0.032s user 0m0.020s sys 0m0.008s If I do time wc -l *.txt | tail it takes real 0m0.156s ...
22
votes
4answers
25k views

Why does “ls | wc -l” show the correct number of files in current directory? [duplicate]

Trying to count number of files in current directory, I found ls -1 | wc -l, which means: send the list of files (where every filename is printed in a new line) to the input of wc, where -l will count ...
3
votes
4answers
512 views

How to display the number of lines, words and characters in separate lines?

I want to display the number of lines, words and characters, in a file, in separate lines? I don't know anymore than using wc filename for this.
5
votes
4answers
203 views

Count lines of non-terminating input

Is there any way to count the lines of a non-terminating input source? For example, I want to run the following for a period of time to count the number of requests: ngrep -W byline port 80 and dst ...
10
votes
3answers
855 views

Why does “wc -c” print a value of one more with echo?

When running echo abcd | wc -c it returns 5. But the word abcd is only 4 characters long. Is echo printing some special character after the word abcd? And can I prevent echo from printing that? ...
3
votes
1answer
492 views

Run wc and display only the word count

I have been trying to create a file called ~/dictwords.txt, which contains the number of words found in the file /usr/share/dict/words. I already created the file then I removed it because I did it ...
11
votes
8answers
3k views

How do I get the character count of words in a particular column?

I have a CSV file like this: abd,123,egypt,78 cde,456,england,45 How can I get the character count of only the 3rd column words? I can't figure out how to get wc to do this.
2
votes
1answer
370 views

Counting the numbers of lines of data as it comes in? [duplicate]

I am currently connected to the Twitter Stream, and I would like to count the number of lines of data as they come in. I know I can do wc-l to just count the lines, but I want it to be auto-updating. ...
5
votes
3answers
3k views

How does word count work for newline (-l)? Number of newlines or lines

I wonder how does wc work? Most times it seems to return the number of lines, but sometimes it seems to be newlines? In the man page its newlines. But: [jiewmeng@JM textFiles]$ echo -e "\n\n" | wc - ...
1
vote
2answers
336 views

How many lines of code are in this file?

I'm trying to figure out how many lines of code I have for files that end in *.pp find . -name *.pp -type f | wc -l 39 I know that I have 39 files, how can I figure out how many lines of code ...
5
votes
2answers
894 views

Counting lines without text in a file

I am using Ubuntu 13.10 for a while now, programming in C++ and Python. I have some question that I can solve by making a program, but maybe there are easier ways, so here is the first question. I ...
0
votes
3answers
8k views

Use of ls with wc command

What does the command : ls | wc -l do? I know wc <filename> gives lines, words, and characters, and wc -l <filename> print the line count. But how it is being used with ls` ...
6
votes
4answers
2k views

How do I get a single total of lines with `wc -l`?

I've added a git alias to give me the line counts of specific files in my history: [alias] lines = !lc() { git ls-files -z ${1} | xargs -0 wc -l; }; lc However, wc -l is reporting multiple totals, ...
2
votes
3answers
3k views

Count number of characters per listed filename

Given the following ls result: $ ls Desktop Documents Downloads Music Pictures Public Templates Videos This will give the total number of characters for all files: $ ls | wc -m 67 But how ...
0
votes
2answers
650 views

Count occurrences of line in multiple files

I have log files that I need to grep and count the number of occurrences of a specific line. Issue is that I must start at a specific line of the first file and only count occurrences after that ...