Pick the column value based on another column from .csv file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Pick the column value based on another column from .csv file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-18-2013
Ganesh L Ganesh L is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 10 April 2014, 7:12 PM EDT
Posts: 19
Thanks: 8
Thanked 1 Time in 1 Post
Pick the column value based on another column from .csv file

My scenario is that I need to pick value from third column based on fourth column value, if fourth column value is 1 then first value of third column.Third column (2|3|4|6|1) values are cancatenated.
Main imp point, in my .csv file, third column is having price value with comma (1,20,300), it has to be considered 1,000 as single column.
Please someone help me to resolve this issue.

Source file format

Code:
column1 column2 column 3 column4 column5
1,ganesh,1,000,2,1
222,ram,2,000,2|3,1
222,ram,5,000,2|3,2
33,raju,5,000,2|5|4|6|1,1
33,raju,5,000,2|8|4|6|1,2
33,raju,5,000,2|9|4|6|1,3
33,raju,5,000,2|8|4|6|1,4
33,raju,5,000,2|3|4|6|1,5

Target output


Code:
column1 column2 column3 column4 
1,ganesh,1,000,2,1
222,ram,2,000,2,1
222,ram,5,000,3,2
33,raju,5,000,2,1
33,raju,5,000,8,2
33,raju,5,000,4,3
33,raju,5,000,6,4
33,raju,5,000,1,5


Last edited by Scott; 01-18-2013 at 04:54 AM.. Reason: Please use code tags
Sponsored Links
    #2  
Old 01-18-2013
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 15 July 2014, 11:14 AM EDT
Location: Houston, Texas, USA
Posts: 675
Thanks: 0
Thanked 203 Times in 195 Posts
try:

Code:
awk -F, '/,/ {split($5,arr, "|"); $5=arr[$6]} 1' OFS=, infile

Sponsored Links
    #3  
Old 01-18-2013
Ganesh L Ganesh L is offline
Registered User
 
Join Date: Jan 2013
Last Activity: 10 April 2014, 7:12 PM EDT
Posts: 19
Thanks: 8
Thanked 1 Time in 1 Post
Thanks for the solution... I will try this code and let u know the status
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Pick the column value based on another column using awk or CUT Ganesh L Shell Programming and Scripting 2 01-09-2013 02:06 AM
Read CSV column value based on column name JohnGG Shell Programming and Scripting 3 11-20-2009 12:33 AM
extract csv based on column value maruthavanan Shell Programming and Scripting 3 11-12-2009 09:55 AM
How to pick values from column based on key values by usin AWK repinementer Shell Programming and Scripting 16 07-24-2009 08:59 AM
sorting csv file based on column selected tententen Shell Programming and Scripting 4 07-05-2009 10:17 PM



All times are GMT -4. The time now is 05:08 AM.