Concatenate string through variable in awk
Hi,
input.tab (pipe-separated): Code:
DATE|PRODUCTS|Customer_A|Customer_B|Customer_C $1: Transaction date $2: describe the order of the different type of products separated by ":" (change from one record to another) $3-$NF: Customer transactions. . Each type of products are separated by ":" and are described in $1 . Numbers at the left and right of the comma are the "purchased" and "sold" items respectively For example, the 01Jan Customer_A: - purchased 0 meat, 21 fruits, 3 dairies - sold 4 meat, 8 fruits, 55 dairy But the 02Jan Customer_A: - purchased 12 fruits, 1 meat, 432 other - sold 0 fruit, 34 meat, 9 other OBJECTIVE: for each date, count the number and list the name(s) of customers who sold fruits, and append the original line: Code:
Number_Customer|Customers|DATE|PRODUCTS|Customer_A|Customer_B|Customer_C MY CODE SO FAR: Code:
gawk ' Code:
Number_Customer|Customers|DATE|PRODUCTS|Customer_A|Customer_B|Customer_C Probably because the NR==1 block keeps the last iteration of the loop... |
I am not sure why you have the 'else' when you are trying to build the customer string as you only want to add the customer when the sold value is greater than zero.
I ended up building my own to see where we differ. Your problem is with your original for loop: Code:
for(j=3; j<=NF; j++){ Here is mine as a comparison: Code:
BEGIN{ FS=OFS="|" } Code:
Number_Customer|Customers|DATE|PRODUCTS|Customer_A|Customer_B|Customer_C |
All times are GMT -5. The time now is 05:34 AM. |