Visit Our UNIX and Linux User Community


Grepping issue..


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Grepping issue..
# 8  
Old 02-28-2008
Question Do you still need an approach?

Previous message implied that you had solved the matter. Do you still need a way to differentiate values?
# 9  
Old 02-28-2008
Thanks for your reply. I'll leave it to your discretion.
# 10  
Old 02-28-2008
Hammer & Screwdriver Since all you are trying to do is determine count...

All it appears that you need is the device size, not the rest of the data when reporting number in that size category. So, I made sample1 and sample2 from your two files. I then ran the following script:

Code:
> cat numcomp
#! /bin/bash

cknum=5242880
count=0
echo $cknum

cat sample1 sample2 >sample3
cat sample3 | cut -d":" -f11 >sample4

echo "TRIAL #1"
cat sample4 | grep $cknum

echo "TRIAL #2"
cat sample4 | grep $cknum >sample5
while read zf
   do
#      echo $zf
      if [ $zf -eq $cknum ]
         then
            echo "Match "$zf
            count=$(($count + 1)) 
         else
            echo "Skipping "$zf
      fi
done <sample5

echo $count" occurences found of "$cknum

It generated output as follows:

Quote:
> numcomp
5242880
TRIAL #1
5242880
5242880
5242880
524288000
524288000
524288000
524288000
524288000
524288000
524288000
524288000
524288000
524288000
524288000
TRIAL #2
Match 5242880
Match 5242880
Match 5242880
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
Skipping 524288000
3 occurences found of 5242880
So, pulling out to only have the size on each line allows through script to do the mathematical match to the number. While you already have another approach to solve the matter, I thought I'd follow-up and present this programming solution. A lot of the code could be eliminated when actually used, I just wanted to show the thought process.

Previous Thread | Next Thread
Test Your Knowledge in Computers #58
Difficulty: Medium
Douglas Engelbart invented the computer mouse.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Performance issue in Grepping large files

I have around 300 files(*.rdf,*.fmb,*.pll,*.ctl,*.sh,*.sql,*.prog) which are of large size. Around 8000 keywords(which will be in the file $keywordfile) needed to be searched inside those files. If a keyword is found in a file..I have to insert the filename,extension,catagoery,keyword,occurrence... (8 Replies)
Discussion started by: millan
8 Replies

2. Shell Programming and Scripting

Grepping more than one word

Dear Experts, Need your help. Typically we use "grep" to search and display a pattern in a txt file. However, here what we want is, we want to grep a line which contains 4 words any where in a line. For example. File has 10,000,000 lines in it out of which there is a particular line which... (1 Reply)
Discussion started by: anushree.a
1 Replies

3. UNIX for Dummies Questions & Answers

Grepping using -w and dashes (-)

I have a script to sort a list of arbitrary hosts and determine if they are supported by grepping them into a master supported list. I cut all the suffixes of the hosts in the arbitrary list, leaving the "short" hostname if you will, then grep -w them into the master list. For example: ... (1 Reply)
Discussion started by: MaindotC
1 Replies

4. Shell Programming and Scripting

grepping by digit

Hi all, Need your help here. I have a file with thousand of lines, as shown in example below KDKJAA 98324 OIDSAJ 324 KJAJAK 100 KJKAJK 89 JOIJOI 21 JDKDJL 12 UOIUOD 10 UDUYDS 8 UIUHKK 6 I would like to grep using... (5 Replies)
Discussion started by: masterpiece
5 Replies

5. UNIX for Dummies Questions & Answers

grepping a variable

I need to pass a parameter that will then be grepped. I need it to grep /paramater and then have a space so if 123 was passed my grep would be grep '/123 ' sample.log this works fine from the command line but when i try and set it searchThis="/$2 " and then run grep $searchThis... (6 Replies)
Discussion started by: magnia
6 Replies

6. UNIX for Dummies Questions & Answers

Help with grepping within variables

I've got a script at the moment that looks like this: if then echo "How many hours would you like users to have logged in for? (single digits)" read hours tim= echo "These are the users who were logged in for $hours... (1 Reply)
Discussion started by: chris_rabz
1 Replies

7. Shell Programming and Scripting

Please help on grepping

Hi All, I have a log file and I want to parse the logfile with a script.A sample text is shown below: I would grep on "return code " on this file. Any idea how the lines above and below the grep patterns could also be extracted. Thanks! nua7 The runLoggingInstall return code is 0... (3 Replies)
Discussion started by: nua7
3 Replies

8. Shell Programming and Scripting

grepping around

Using shell scripts, I use grep to find the word “error” in a log file: grep error this.log. How can I print or get the line 3 lines below the line that word “error” is located? Thanks in advance for your response. (9 Replies)
Discussion started by: cbeauty
9 Replies

9. UNIX for Dummies Questions & Answers

grepping for a sentence

Can you grep for a sentence. I have to search logs everyday at work and I was wondering if I could search for a string of words instead of just one. for example, if I had to find this sentence: "Received HTTP message type" How would I grep it (2 Replies)
Discussion started by: eloquent99
2 Replies

10. UNIX for Dummies Questions & Answers

grepping

Is there a way to grep for something and then print out 10 lines after it. for example if I want to grep for a word, then output the following 10 or whatever number of lines after the word. (5 Replies)
Discussion started by: eloquent99
5 Replies

Featured Tech Videos