# Multiple Parameter search script - OLD Post

**URL:** <https://community.unix.com/t/multiple-parameter-search-script-old-post/368701>\
**Category:** Shell Programming and Scripting\
**Created:** [October 8, 2017, 11:24am UTC](https://community.unix.com/t/multiple-parameter-search-script-old-post/368701 "2017-10-08T11:24:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![chetanojha](https://community.unix.com/letter_avatar/chetanojha/32/5_5575768a8748004e209b776fc1b2916d.png) [@chetanojha](https://community.unix.com/u/chetanojha)\
**Post date:** [October 8, 2017, 11:24am UTC](https://community.unix.com/t/multiple-parameter-search-script-old-post/368701/1 "2017-10-08T11:24:16Z")

</div>

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

> **[CSV File with Multiple Search Parameter](https://www.unix.com/shell-programming-and-scripting/271407-csv-file-multiple-search-parameter.html)**
>
> 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). pre { overflow:scrol | The UNIX and Linux Forums

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](http://www.unix.com/302993333-post5.html)

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:

```plaintext
 ./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

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [October 8, 2017, 1:04pm UTC](https://community.unix.com/t/multiple-parameter-search-script-old-post/368701/2 "2017-10-08T13:04:43Z")

</div>

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)?

---

<div class="post-metadata">

**Author:** ![chetanojha](https://community.unix.com/letter_avatar/chetanojha/32/5_5575768a8748004e209b776fc1b2916d.png) [@chetanojha](https://community.unix.com/u/chetanojha)\
**Post date:** [October 8, 2017, 3:40pm UTC](https://community.unix.com/t/multiple-parameter-search-script-old-post/368701/3 "2017-10-08T15:40:26Z")

</div>

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).

```nohighlight
"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.

```nohighlight
./findInvoice.sh MICHELIN 03032017

```

Output of the script will give me

```nohighlight
990001 MICHELIN

```

OR

```nohighlight
990001

```

Another example is

```nohighlight
./findInvoice.sh PIRELLI 03032017

```

and output of the script will be

```nohighlight
990002 PIRELLI

```

OR

```nohighlight
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

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/5_5575768a8748004e209b776fc1b2916d.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [October 9, 2017, 4:06am UTC](https://community.unix.com/t/multiple-parameter-search-script-old-post/368701/4 "2017-10-09T04:06:37Z")

</div>

Still unclear. Would this help:

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

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

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

```

If not, become more specific...
