Best search technique


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Best search technique
# 8  
Old 03-29-2010
Sorry, I don't understand the requirement (may be it's just me, so I'll wait to see what other forum members think).
# 9  
Old 03-29-2010
In + out example = easier to make solution.
Code:
function lookfor {
y=$1
s=$2
echo -e "NOW Processing file: $s \n\n"
cat $s | while read file
do    
        [ "${#file}" -lt 5 ] && continue
        awk -v file=$file '$0 ~ file  {print $2}' $file | sort -u > $$.tmp
        cnt=$(cat $$.tmp | wc -l)
        ((cnt == 1)) && cat $$.tmp >> fnd.txt
done
}

######################
> fnd.txt
lookfor "hugelog1.log" "firstRowUniq.1" 
lookfor "hugelog2.log" "firstRowUniq.2" 
lookfor "hugelog3.log" "firstRowUniq.3" 

rm -f $$.tmp 2>/dev/null

# 10  
Old 03-30-2010
@kshji
Thanks for the script but seems like I get some erros on variable file etc ... I tried to fix but it is also running slow.

I tried a differnt approach all in awk: I get quick and correct result except for the last row. Any ideas or suggestion.

did a sort on the file and then the below code.
Code:
awk '
{
 if ( $1==t )
  {
      if ( $2 == o ) { cnd=cnd+1 } else { cnd=0 }
    }

if ( $1 != t )
     {
     if (cnd > 0 )
     {
       print "Found=>",t,o,cnd;
       cnd=0;
      }
 else
    {
        cnd=0
     }
   }

#print "Processed", $1,$2;
t=$1;o=$2;
}

' filename_here

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. What is on Your Mind?

YouTube: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search

Getting a bit more comfortable making quick YT videos in 4K, here is: Search Engine Optimization | How To Fix Soft 404 Errors and A.I. Tales from Google Search Console https://youtu.be/I6b9T2qcqFo (0 Replies)
Discussion started by: Neo
0 Replies

2. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

4. Linux

Best Compression technique ?

Hi all, I am working on a sample backup code, where i read the files per 7200 bytes and send it to server. Before sending to server, i compress each 7200 bytes using zlib compression algorithm using dictionary max length of 1.5 MB . I find zlib is slow. Can anyone recommend me a... (3 Replies)
Discussion started by: selvarajvss
3 Replies

5. Shell Programming and Scripting

Password Obscuring Technique

Hi, We have a unix shell script which tries login to database. The user name and password to connect to database is stored in a file connection.sql. Now connection.sql has contents def ora_user =&1 CONNECT A_PROXY/abc123@DEV01 When on UNIX server we connect to database and set spool on... (7 Replies)
Discussion started by: Gangadhar Reddy
7 Replies

6. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

7. UNIX for Dummies Questions & Answers

FORK/EXEC technique

Hi! Can someone explain me exactly this technique? Why a process (PARENT) creates a copy of itself with FORK (CHILD)? What's the reason of this behaviour? Sorry, but I cannot understand the logic behind it. Thanks. (4 Replies)
Discussion started by: marshmallow
4 Replies

8. UNIX for Dummies Questions & Answers

Difference Technique's???

Is there any better way of doing this? I only want to find a status of a diff, ie diff the file and return to me whether it is different or not or non-existant. This example works, however I think it could be less messier: workd=`pwd`;find $workd -name "*.sum" | while read line ; do... (1 Reply)
Discussion started by: Shakey21
1 Replies
Login or Register to Ask a Question