Multiple Parameter search script - OLD Post

Dear Forum Member,
Hope you are well. I am sending this email to your reply to one of my post in the forum. I raised an help request from all of you regarding an issue I was facing. The original thread is here

I received many helpful replies and one in particular helped a lot along with all other replies.. Link to that reply is below too.

CSV File with Multiple Search Parameter Post: 302993333

The code in the above thread worked like a charm for me till now. Especially multiple input parameters. But I ended up in a situation where I want to pick only rows from the file where both input parameters are present. For Example:

 ./script.sh HYUNDAI 990001 

Currently the code returns "all" the values or rows where either HYUNDAI or 990001 is present. But I want to restrict the code to return only rows which have both the above parameters in the same row.

Thanks for all your previous replies... which have tremendously helped me.

Thanks.
C

Please be more specific, post the code you want modified and an input sample that represents your real data. Don't have people read to and fro and guess which of the posts referred are meaningful for your new problem and which aren't.

And, will the parameters always come in two? Or more? In the same order? The invoice No. after the vendor (this is relevant, as they are treated diffrently)?

Dear Team Members,

I have a unique problem. Below is the dataset which I have. I am writing a script which will read through the file and pull the invoice no. (Field 2 of C1 row).

"C1",990001,"L1","HERO","MOTORCYCLE","ASIA-PACIFIC","BEIJING"
"C2","CLUTCH","HYUNDAI",03032017
"C2","BRAKES","EUROPARTS",03032017
"C2","TYRES","MICHELIN",03032017

"C1",990002,"L2","HERO","CAR","EU1","BUDAPEST"
"C2","CLUTCH","FORD",03032017
"C2","BRAKES","EUROPARTS",03032017
"C2","TYRES","PIRELLI",03032017

For example. My script needs to accept parameters like TYRES MICHELIN.
Script will search the file for the C2 rows and where ever it will find the above two parameters (In the same row/record) - it will bring the Invoice number along with the MICHELIN from respective C1 rows. It will also remove the doubt quotes from the texts.

./findInvoice.sh MICHELIN 03032017

Output of the script will give me

990001 MICHELIN

OR

990001

Another example is

./findInvoice.sh PIRELLI 03032017

and output of the script will be

990002 PIRELLI

OR

990002

Any help would be useful.

There is a similar thread which I opened before but that had a little different requirement...if somebody want to see - its here

Thanks

Still unclear. Would this help:

awk -F, -v ITM="$*" '
BEGIN           {sub (/ /, ".*", ITM)
                }

$1 == "\"C1\""  {INV = $2
                 next
                }

match ($0, ITM) {print INV
                }
' file

If not, become more specific...