Help with grep & count in ksh


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help with grep & count in ksh
# 15  
Old 10-06-2011
Thanks Scrutinizer.

But the grep does not give me the count of words present in the file.

Thanks

---------- Post updated at 03:22 PM ---------- Previous update was at 03:19 PM ----------

I used this to test what it does
Code:
var=`nawk '{n+=gsub("esdev","",tolower($0))}END{print n}' $path`
echo value is $var

the echoed value is 5 for the following file
Quote:
No.esDEV.Queue|No.Receive.Queue|||n|120|No_User||No_User|
No.Send.Queue|No.Receive.Queue|||n|120|No_User||No_User|
# 16  
Old 10-06-2011
That's right but I figured that since you were only testing for zero occurences, that did not matter. If you need the count then you could try something like this:
Code:
if occ=$(grep -ci esprd infile)
then 
  echo "failure with $occ occurrences"
  exit 1
else
  echo success
fi

# 17  
Old 10-06-2011
Quote:
Originally Posted by Green_Star
Thanks Scrutinizer.

But the grep does not give me the count of words present in the file.

Thanks

---------- Post updated at 03:22 PM ---------- Previous update was at 03:19 PM ----------

I used this to test what it does
Code:
var=`nawk '{n+=gsub("esdev","",tolower($0))}END{print n}' $path`
echo value is $var

the echoed value is 5 for the following file
for the quoted file, I get the expected value of 1 for '$var'
# 18  
Old 10-07-2011
Quote:
Originally Posted by vgersh99
for the quoted file, I get the expected value of 1 for '$var'
oh really. Nice.

Which shell are you using? I am using Korn Shell. Thanks
# 19  
Old 10-07-2011
Quote:
Originally Posted by Green_Star
oh really. Nice.

Which shell are you using? I am using Korn Shell. Thanks
either ksh or bash.
# 20  
Old 10-07-2011
That should work in just about any shell though. There's not a lot to it -- awk does everything.

It may be that your awk is misbehaving. What's your system?
# 21  
Old 10-07-2011
OOH!!! Now it works.

Thanks a lot to all of you. It was really nice help from everyone of you.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Inconsistent `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l`

i have this line of code that looks for the same file if it is currently running and returns the count. `ps -eaf -o args | grep -i sfs_pcard_load_file.ksh | grep -v grep | wc -l` basically it is assigned to a variable ISRUNNING=`ps -eaf -o args | grep -i sfs_pcard_load_file.ksh |... (6 Replies)
Discussion started by: wtolentino
6 Replies

2. Shell Programming and Scripting

Count & Result

Hi All. I'm trying to count with command cat Count.log |sort -t 1 | uniq -c Input File. Back-end Invalid Id Password Back-end Invalid Id Password Success Success Success Back-end Invalid Id Password Back-end User state is invalid Back-end User state is invalid Success... (9 Replies)
Discussion started by: ooilinlove
9 Replies

3. UNIX for Dummies Questions & Answers

How do I count how many times a specific word appear in a file (ksh)?

Hi Please can you help how do I count the number of specific characters or words that appear in a file? (8 Replies)
Discussion started by: fretagi
8 Replies

4. Shell Programming and Scripting

KSH: Split String into smaller substrings based on count

KSH HP-SOL-Lin Cannot use xAWK I have several strings that are quite long and i want to break them down into smaller substrings. What I have String = "word1 word2 word3 word4 .....wordx" What I want String1="word1 word2" String2="word 3 word4" String3="word4 word5" Stringx="wordx... (5 Replies)
Discussion started by: nitrobass24
5 Replies

5. Shell Programming and Scripting

Count lines and use if then ksh

I try to count number of lines of a data.txt file and then if number of lines is greater than 1 then email me the file. I could not find what is wrong with my code, hope you can point out the mistake i made #! /bin/ksh count =`cat /from/file/data.txt | wc -l` if ]; then mailx -s... (4 Replies)
Discussion started by: sabercats
4 Replies

6. Shell Programming and Scripting

Using Grep & find & while read line in a script

Hello people! I would like to create one script following this stage I have one directory with 100 files File001 File002 ... File100 (This is the format of content of the 100 files) 2012/03/10 12:56:50:221875936 1292800448912 12345 0x00 0x04 0 then I have one... (0 Replies)
Discussion started by: Abv_mx81
0 Replies

7. UNIX for Dummies Questions & Answers

Grep char count & pipe to sed command

Hi I am having a 'grep' headache Here is the contents of my file: (PBZ,CP,(((ME,PBZ,BtM),ON),((ME,((PBZ,DG),(CW9,PG11))),CW9,TS2,RT1))) I would like to count out how many times 'PBZ' occurs and then place that number in the line above 3... (8 Replies)
Discussion started by: cavanac2
8 Replies

8. Shell Programming and Scripting

combination between || and && in IF condition with ksh

Dear All, Please advice about this issue. when i run this line in a script if && || && || && if i enter $x = test3 and $y = test1 the If condition apply while it should not Best Regards (2 Replies)
Discussion started by: islam.said
2 Replies

9. UNIX for Dummies Questions & Answers

Difference between grep, egrep & grep -i

Hi All, Please i need to know the difference between grep, egrep & grep -i when used to serach through a file. My platform is SunOS 5.9 & i'm using the korn shell. Regards, - divroro12 - (2 Replies)
Discussion started by: divroro12
2 Replies

10. UNIX for Dummies Questions & Answers

Sorting using count, grep and count

Hi, I trying to sort information in a file by making count for every object. For example: A B A D A B C i would like to sort out count for each object (A's, B's and etc) but in actual case i dont know the object but i know the position ofthe object. do i need to use array as well? Any... (2 Replies)
Discussion started by: sukhpal_78
2 Replies
Login or Register to Ask a Question