Count Command Help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count Command Help
# 8  
Old 09-25-2014
Hi, from the man page (man wc):
Code:
If no files are specified, the standard input is used and no file name is
     displayed.

By using <, the input to the command is standard input (stdin, which is redirected from the file).
This User Gave Thanks to Scrutinizer For This Post:
# 9  
Old 09-25-2014
Quote:
Originally Posted by kadawtomtom978
Lols, that was a simple fix. Thanks a bunch!Smilie

Also, like I mentioned earlier. I'm very new to this. How did your code fix my issue?
Expanding on what Scrutinizer said...

When the wc utility is given one or more operands, it reads from the named file(s) and prints the number of complete lines in each file and the file's name(s). (If more than one operand is given, it also prints a total line at the end.)

When no operands are given, wc reads from standard input and only prints the number of complete lines it found.

If you don't mind reversing the order (# of lines before file name) and you don't mind the total line at the end, this should be much more efficient:
Code:
#!/bin/sh
cd /data/test/input
wc *.dat >> dat_results.out

This User Gave Thanks to Don Cragun For This Post:
# 10  
Old 09-25-2014
Thank You both for the explanation.
# 11  
Old 09-26-2014
I apologize, I omitted an option from the script I suggested earlier. It should have been:
Code:
#!/bin/sh
cd /data/test/input
wc -l *.dat >> dat_results.out

And, of course, you want > instead of >> if you want to replace the previous contents of the output file instead of appending your new results to the end of the existing contents of dat_results.out.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get count of multiple word in single command

Hello Experts, I have a log file that contains 4 different type of exception : 1- Exception 2- Fatal 3- Error 4- Exec My requirement is to find count of each type of exception, i tried using combination of -E and -C but that doesn't seems to be working : grep -ec 'Exception' -ec... (4 Replies)
Discussion started by: mukulverma2408
4 Replies

2. Shell Programming and Scripting

Count aggregated command output using wc -l

Hi all, I need to run a bunch of commands seperated by ; but then count the total lines of output. Pipes and redirection don't seem to be helping me. Anyone know how I can do this properly: ls /usr/bin/nslookup ; ls /usr/sbin/lsof ; ls /sbin/ifconfig ; ls /usr/sbin/dmidecode ; ls... (2 Replies)
Discussion started by: dan-e
2 Replies

3. Shell Programming and Scripting

Grep command to count characters

I have a file that I need to count the number of "Y"s in the file, but just the "Y"s that fall between certain columns. Like: file1: 1234567890123456789012345 BBBBBBYBBBBYBBYBBYBBYBBB I want to count the 'Y's between 17 and 21 = 2 "Y"s Thanks (12 Replies)
Discussion started by: jbt828
12 Replies

4. UNIX for Dummies Questions & Answers

count and content in the same command

Hi, I have small query and a understanding, could you please clarify the query and correct my understanding..? I am very big log file If i need to take a count and contained lines for a particular pattern/word i am using the grep command twice like the below. grep -c "OutOfMemoryException"... (4 Replies)
Discussion started by: senthilkumar_ak
4 Replies

5. UNIX for Dummies Questions & Answers

Word Count (WC) command

I have created a file "pat".This file contains the text "abcdefghi". Now i want to count the characters in this file "pat". I gave wc -c | pat and it returns me exact count "9". Now when i tried like "echo pat | wc -m" It returns '4'. as for as i understand this command "echo pat | wc -m" should... (7 Replies)
Discussion started by: mdali_vl
7 Replies

6. UNIX for Dummies Questions & Answers

Record count problem using sed command

Hi, I have a script which removes 2 header records and 1 trailer record in a list of files. The commands doing the actions are sed '1,2d' $file > tempfile1.dat sed '$d' < tempfile1.dat > $output.txt Its working fine for all records except a file having size=1445509814 and number of... (2 Replies)
Discussion started by: ayanbiswas
2 Replies

7. UNIX for Dummies Questions & Answers

Problem count with wc-l command

Hi All, I'm trying to count how many line in my *.txt file. My *.txt file has 1937 lines. The problem is : when I use wc -l command the result is 1936. Again, I did some test. I create a new file with 100 lines with text editor (Notepad ++, Ultra edit). And when I count it again with wc... (2 Replies)
Discussion started by: kunimi
2 Replies

8. UNIX for Dummies Questions & Answers

command to get count in unzipped folder

Hi All, Is there is a way to do this in a single unix command I have unzipped some files into a directory .. I want to check the count of the files in the directory and also i need to check whether the files is having read permision or not.. I know it can be done by a script isthere... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies

9. Shell Programming and Scripting

byte count and cut command

1. Is there a way to count the number of bytes of a variable? example: abc@yahoo.com is 13 bytes 2. Cut command only allows one byte for delimiter example: cut -f1 -d'.' delimited by period. Is there a way to have two or more characters in the delimiter field? thanks in adavance. :) (4 Replies)
Discussion started by: hemangjani
4 Replies

10. Shell Programming and Scripting

command to count files in dir

hi plz let me know the command to count the files in directory. thanks in advance -Bali Reddy (4 Replies)
Discussion started by: balireddy_77
4 Replies
Login or Register to Ask a Question