Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Multiple Parameter search script - OLD Post

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 2 Weeks Ago
chetanojha chetanojha is offline
Registered User
 
Join Date: Jan 2015
Last Activity: 8 October 2017, 4:24 PM EDT
Posts: 24
Thanks: 19
Thanked 0 Times in 0 Posts
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


https://www.unix.com/shell-programmin...parameter.html

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

https://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:


Code:
 ./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

Last edited by Scott; 2 Weeks Ago at 04:03 PM.. Reason: Added code tags
Sponsored Links
    #2  
Old Unix and Linux 2 Weeks Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 October 2017, 5:17 PM EDT
Location: Aachen, Germany
Posts: 11,483
Thanks: 310
Thanked 3,561 Times in 3,276 Posts
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)?
Sponsored Links
    #3  
Old Unix and Linux 2 Weeks Ago
chetanojha chetanojha is offline
Registered User
 
Join Date: Jan 2015
Last Activity: 8 October 2017, 4:24 PM EDT
Posts: 24
Thanks: 19
Thanked 0 Times in 0 Posts
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).

Code:
"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.

Code:
./findInvoice.sh MICHELIN 03032017

Output of the script will give me

Code:
990001 MICHELIN

OR

Code:
990001

Another example is

Code:
./findInvoice.sh PIRELLI 03032017

and output of the script will be

Code:
990002 PIRELLI

OR

Code:
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

Last edited by Scott; 2 Weeks Ago at 04:02 PM.. Reason: Please use code tags
    #4  
Old Unix and Linux 1 Week Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 22 October 2017, 5:17 PM EDT
Location: Aachen, Germany
Posts: 11,483
Thanks: 310
Thanked 3,561 Times in 3,276 Posts
Still unclear. Would this help:

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

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

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

If not, become more specific...
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
CSV File with Multiple Search Parameter chetanojha Shell Programming and Scripting 13 03-09-2017 11:54 AM
Search and replace multiple patterns in a particular column only - efficient script ss112233 Shell Programming and Scripting 6 12-01-2014 03:39 PM
Passing parameter to script, and split the parameter only4satish Shell Programming and Scripting 5 11-01-2012 05:37 AM
Complex Search/Replace Multiple Files Script Needed UCCCC Shell Programming and Scripting 2 07-22-2009 12:06 PM
multiple input search and replace script tungaw2004 UNIX for Dummies Questions & Answers 3 04-29-2007 07:59 AM



All times are GMT -4. The time now is 10:28 PM.