|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
Where condition in grep or awk?
Dear All, I need help.. I am having a csv file. Code:
Home_TITLE,People_TITLE,Repo_ALIAS HMN5530,RKY5807,/mine_repo/rike001 HMN5530,SRY6443,/mine_repo/rike001 HMN5530,ARDY001,/mine_repo/rike001 If i have two value in varible RKY5807, HMN5530. how can fetch and store another value Repo_ALIAS (/mine_repo/rike001) in variable. its very much similar to put where clause but i have no idea Thank you for your help.
Last edited by zaxxon; 02-15-2013 at 08:07 AM.. Reason: code tags, see PM |
| Sponsored Links | ||
|
|
#2
|
|||
|
|||
|
Try something like this: Code:
var1="RKY5807"
var2="HMN55303"
new_var=$(awk -F"," -v v1="$var1" -v v2="$var2" '$1==v1 && $2==v2{print $3}') |
| The Following User Says Thank You to Franklin52 For This Useful Post: | ||
yadavricky (02-15-2013) | ||
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
Its not working Please let me know if you have some other option. ---------- Post updated at 10:56 AM ---------- Previous update was at 10:47 AM ---------- Code:
awk -F "," '/AVE5530/&&/EFC6145/ {print $3}' WiseReference.csvIf i give value directly then it is working fine Code:
awk -F "," '/$var1/&&/$var2/ {print $3}' WiseReference.csvit is not giving any output please help Last edited by Franklin52; 02-18-2013 at 02:33 AM.. Reason: Please use code tags for data and code samples |
|
#4
|
|||
|
|||
|
Try this: Code:
awk -F "," -v var1="AVE5530" -v var2="EFC6145" '/var1/&&/var2/ {print $3}' WiseReference.csv |
| Sponsored Links | |
|
|
#5
|
|||
|
|||
|
No its not working can you please check i am getting the blank value
|
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
Quote:
panyam's suggestion has a small mistake in it. Try this: Code:
awk -F "," -v var1="AVE5530" -v var2="EFC6145" '(var1 ~ $0) &&(var2 ~ $0) {print $3}' WiseReference.csv |
| Sponsored Links | |
|
|
#7
|
||||
|
||||
|
Quote:
Try this: Code:
awk -F, -v var1="HMN5530" -v var2="RKY5807" '$1==var1&&$2==var2{print $3}' WiseReference.csv |
| Sponsored Links | ||
|
![]() |
| Tags |
| where clause awk |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| grep not equal to condition | prash358 | Shell Programming and Scripting | 6 | 08-22-2012 05:26 PM |
| HELP with AWK one-liner. Need to employ an If condition inside AWK to check for array variable ? | shell_boy23 | Shell Programming and Scripting | 6 | 07-10-2012 05:20 AM |
| grep in the if condition | boopal | Shell Programming and Scripting | 8 | 12-09-2011 11:17 AM |
| use awk pick value from lines as condition for grep | jackoverflow | Shell Programming and Scripting | 2 | 06-24-2010 06:37 PM |
| grep command with AND condition | prasperl | Shell Programming and Scripting | 6 | 01-26-2010 03:54 AM |
|
|