`wc` utility counts newline, word, and byte for file(s) or standard input.
22
votes
3answers
839 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 ...
0
votes
2answers
44 views
Why do wc get wrong result in
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 ...
1
vote
2answers
71 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
51 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
20 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
829 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
62 views
How to create new script , role like wc [closed]
I would like to create a new .wc command , but I have no idea how to proceed.
Can you help me?
0
votes
1answer
43 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 (...
4
votes
1answer
481 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 ...
0
votes
1answer
47 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 ...
2
votes
1answer
51 views
How to find files with same name but different line count in two directories?
I have a directory sub1 with the following files:
$ wc -l *
5 file1.csv
5 file3.csv
1 file4.csv
In sub2, I have the following:
$ wc -l *
5 file1.csv
5 file2.csv
1 file3.csv
5 file4.csv
1 file5.csv
...
3
votes
5answers
935 views
The result of “ls | wc -l” does not match the real number of files [duplicate]
I need to count the number of files under a folder and use the following command.
cd testfolder
bash-4.1$ ls | wc -l
6
In fact, there are only five files under this folder,
bash-4.1$ ls
total 44
-...
3
votes
1answer
329 views
How to count occurances of phrase in grep, ignoring case?
I need to search for a name nicolas bomber with grep. Name can also be NiCoLaS BomBer. I need to run a .sh file which display the number of occurrences of that name.
The command I made is this one:
...
-2
votes
1answer
147 views
cat command appears to be adding extra $ character at the end of each line
I am trying to create a file and it looks like the vi editor is adding a $ at the end of each line. I don't know what's causing this or how to prevent vi from doing it.
vi file.txt
12345
abcde
cat -...
-1
votes
4answers
435 views
What will ls -l | wc -l command display?
Will:
ls -l|wc -l
Display the number of devices too? (Including files and directories)
0
votes
0answers
124 views
Count and compare files in Linux
I want to just compare the number of lines in two files. Below is the list of names of files. One file contains names/location of fastq files; the other file contains names/location of bam files.
...
0
votes
3answers
123 views
Command to print the number of *.pdf files in a chosen directory [duplicate]
I am currently not on a Linux machine. Would the following command produce my wanted result?
ls | grep ".pdf" | wc
3
votes
2answers
382 views
How can I find files with a long first line?
currently I have a problem with a server. One user who is hosting a lot of sites got hacked and some of his php files were modified. Now I want to get a list of the infected files and also want to ...
1
vote
1answer
58 views
Save number of lines output to a variable in a shell script without consuming the output
I have a shell script where I have a if statement based off of the number output lines output from another call. (In my case do something there is more that 1 line of output).
LINES=$(function_call | ...
0
votes
1answer
244 views
How do I count the number of files in all subdirectories and add the counts together
I am trying to count the number of file in each directory/subdirectory, add them together and get a total which I can then compare to another directory:
#!/bin/bash
echo "Checking directories for ...
0
votes
2answers
109 views
wc -l command issues in SunOs to Linux migration
We are migrating from SunOS to Linux. I'm facing some problem with wc -l command. When I used wc -l <file_name>, SunOS is giving leading spaces before count where as Linux there are no leading ...
0
votes
1answer
36 views
Count ONLY alphanumeric words in a specific column of a file
It's essentially what the title says - 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 ...
11
votes
2answers
2k views
Need something that is faster than “wc -l”
For a really big file like 1GB wc -l happens to be slow. Do we have a faster way calculating the number of newlines for a particular file?
7
votes
3answers
751 views
wc command counts extra characters
cat > file
Amy looked at her watch. He was late. The sun was setting but Jake didn’t care.
wc file
1 16 82 file
Can somebody explain why wc command returns 3 extra characters in this ...
0
votes
1answer
104 views
Append row count and date to filename
Is there a way to append both a row count and a date to a filename? I have a file I am creating in SAP and upon output I would like to run a script to change the filename per my client's ...
0
votes
2answers
228 views
bash shell loop through directory listing contents and executability
I'm currently working on a homework assignment and I need to take a given directory path and from that list the files and directories in it. While also including if it's executable or not. I'm also ...
2
votes
4answers
787 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
35 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,...
1
vote
5answers
405 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?
1
vote
5answers
273 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
176 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
less ...
1
vote
4answers
271 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
589 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
279 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
250 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
231 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
114 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
69 views
Big XML - copy data from nth Occurrences to another file
<XML>
<Employee>
<firstname></firstname><lastname></lastname>
</Employee>
<Employee>
<firstname></firstname><lastname></lastname>...
0
votes
1answer
45 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 .
/appl/exe/13/dat&...
0
votes
2answers
801 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
75 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
975 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
2k 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
202 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 ...
20
votes
15answers
2k 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
261 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-$...
3
votes
1answer
142 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
74 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
188 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
145 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 ...