Multiple Parameter search script - OLD Post


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Multiple Parameter search script - OLD Post
# 1  
Old 10-08-2017
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


CSV File with Multiple Search Parameter

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; 10-08-2017 at 05:03 PM.. Reason: Added code tags
# 2  
Old 10-08-2017
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)?
# 3  
Old 10-08-2017
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; 10-08-2017 at 05:02 PM.. Reason: Please use code tags
# 4  
Old 10-09-2017
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...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. Shell Programming and Scripting

Replace multiple file by passing parameter value

Hello All, I want to change date part in file name to yesterday date in the file name. example file name file-12122017-06-30-41.dat want file-12112017-06-30-41.dat I am doing like below. Below it is not changing the filename. Actually it is not parsing the $today and $yesterday value in... (1 Reply)
Discussion started by: looney
1 Replies

3. Shell Programming and Scripting

CSV File with Multiple Search Parameter

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... (13 Replies)
Discussion started by: chetanojha
13 Replies

4. UNIX for Dummies Questions & Answers

Search file and print everything except multiple search terms

I'm trying to find a way to search a range of similar words in a file. I tried using sed but can't get it right:sed 's/\(ca01\)*//'It only removes "ca01" but leaves the rest of the word. I still want the rest of the information on the lines just not these specific words listed below. Any... (3 Replies)
Discussion started by: seekryts15
3 Replies

5. Shell Programming and Scripting

Call Script with Parameter (that has another parameter)

Hi. How do I achieve this sh /EDWH-DMT02/script/MISC/exec_sql.sh "@/EDWH-DMT02/script/others/CSM_CKC/Complete_List.sql ${file_name}" Complete_List.txt The /EDWH-DMT02/script/MISC/exec_sql.sh has two parameters and it's working fine with this sh /EDWH-DMT02/script/MISC/exec_sql.sh... (7 Replies)
Discussion started by: aimy
7 Replies

6. Shell Programming and Scripting

Search and replace multiple patterns in a particular column only - efficient script

Hi Bigshots, I have a pattern file with two columns. I have another data file. If column 1 in the pattern file appears as the 4th column in the data file, I need to replace it (4th column of data file) with column 2 of the pattern file. If the pattern is found in any other column, it should not... (6 Replies)
Discussion started by: ss112233
6 Replies

7. Shell Programming and Scripting

Passing parameter to script, and split the parameter

i am passing input parameter 'one_two' to the script , the script output should display the result as below one_1two one_2two one_3two if then echo " Usage : <$0> <DATABASE> " exit 0 else for DB in 1 2 3 do DBname=`$DATABASE | awk -F "_" '{print $1_${DB}_$2}` done fi (5 Replies)
Discussion started by: only4satish
5 Replies

8. Shell Programming and Scripting

need help with post:extract multiple columns from multiple files

hello, I will would be grateful if anyone can help me reply to my post extract multiple cloumns from multiple files; skip rows and include filenames; awk Please see this thread. Thanks manishabh (0 Replies)
Discussion started by: manishabh
0 Replies

9. Shell Programming and Scripting

Complex Search/Replace Multiple Files Script Needed

I have a rather complicated search and replace I need to do among several dozen files and over a hundred occurrences. My site is written in PHP and throughout the old code, you will find things like die("Operation Aborted due to....."); For my new design skins for the site, I need to get... (2 Replies)
Discussion started by: UCCCC
2 Replies

10. UNIX for Dummies Questions & Answers

multiple input search and replace script

hi, i want to create a script that will search and replace the values inside a particular file. i have 5 files that i need to change some values inside and i don't want to use vi to edit these files. All the inputted values on the script below will be passed into the files. cho "" echo... (3 Replies)
Discussion started by: tungaw2004
3 Replies
Login or Register to Ask a Question