The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM



View Single Post in UNIX Forums - Click on the Thread or Permalink to View Entire Thread -->
  #12 (permalink)  
Old 10-31-2006
napolayan napolayan is offline
Registered User
 

Join Date: Oct 2006
Location: Bangalore, India
Posts: 41
Quote:
Originally Posted by anbu23
Code:
#!/bin/ksh

awk -v check_val="$1" '{
        if( $0==check_val) { key[$0]++ }
        if(key[$0] < 2 ) print $0
       }' inputfile > outputfile
umm..how abt this?

awk '/$1/' inputfile>temp

awk '{for ( $0 in `cat temp` )
key[$0]++
if(key[$0] < 2 ) print $0
}' inputfile > outputfile


i didnt try this out, but i hope the logic is clear. i searched for the pattern specified by $1 and stored all the matches in temp. then instead of a direct comparison with 'if', i matched $0 with all the values in temp using a for loop. rest of the logic is the same. pardon any syntactical errors.
Reply With Quote