There are many ways to do it, this method uses ask, grep & sort to do the job
Assumptions:
- Files are pipe ("|") separated
- File containing the key is called "accounts"
- Columns 2 & 4 join to form the key to be used for filtering
- File containing the records to be filtered is called "acdata"
- This file contains the "key" column apart from other data
- Filtered records need to be stored in the file "filtdata"
awk 'BEGIN { FS="|";} {k1=$2; k2=$4; k=k1 k2; print "grep " k " acdata" ;}' accounts | sort -u | bash > filtdata
Sort with unique option turned on needs to be used to ensure that we get only one row from the key file in case there are more than one rows with the same composite key.
No comments:
Post a Comment