![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Filtering and Grouping: A Comparison of SQL, Linux Scripting, and Ruby | iBot | Oracle Updates (RSS) | 0 | 04-06-2008 02:10 AM |
| Grouping and summing data through unix | pcharanraj | Shell Programming and Scripting | 1 | 12-14-2007 06:20 AM |
| grouping of numbers with script | cdfd123 | Shell Programming and Scripting | 2 | 11-01-2007 01:37 PM |
| grouping of objects and print their number | cdfd123 | Shell Programming and Scripting | 3 | 10-03-2007 10:49 PM |
| egrep and grouping | effigy | Shell Programming and Scripting | 1 | 10-14-2004 07:45 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
awk - Grouping lines
Hi All
I have the input file as INFOR00028114 GRAINS BAKERY 4000 INFOR00028114 GRAINS BAKERY 4000 INFOR00028114 GRAINS BAKERY 4000 INFOR0009183-RIVERS - IC 2672 INFOR0009183-RIVERS - IC 2672 INFOR0009183-RIVERS - IC 2672 INFOR0009183-RIVERS - IC 2671 I want the output like BRAND 14 GRAINS BAKERY 000281 3 4000 BRAND 3-RIVERS - IC 000918 1 2671 BRAND 3-RIVERS - IC 000918 3 2672 BRAND 5 STAR 001972 2 3618 The Layout would be like postion 1-5 for NAME1 position 6-6 for NAME2 position 12-41 for NAME3 position 42-46 for NAME4 I framed the below logic but i am getting the output like BRAND 14 GRAINS BAKERY 000281 3 4000 BRAND 3-RIVERS - IC 000918 1 2671 BRAND 5 STAR 001972 2 3618 which is not that expected. awk '{ c[$0]++ a=substr($0,1,5) b=substr($0,12,30) ff=substr($0,6,6) d=substr($0,42,4) j[a" "b" "ff]=c[$0]" " d }END {for(i in j) print i, j[i]}' tes|sort I am not sure what needs to be changed. Can any one help me? Regards Dhana |
| Forum Sponsor | ||
|
|
|
|||
|
Awk - Grouping Lines
Hi
I framed the below awk script awk '{ key=substr($0,1,41) key1=substr($0,1,11) curr=$NF c[key]++ curr=arr[key] curr_key=key arr[key]= sprintf("%s %-50s %6s %-6s %s",substr($0,1,5),substr($0,12,30),substr($0,6,6),c[key],$NF) prev_key=curr_key prev=curr } END {for (i in arr) {print arr[i]} } ' /HS_Data_00/tmp/test/tes | sort When the input file is VARTY002639DUTCHY 4000 VARTY0026592% REDUCED FAT RC 3590 VARTY0026592% REDUCED FAT RC 3590 VARTY0026592% REDUCED FAT RC 3590 VARTY002660SACCHET 3360 VARTY0026621.5% REDUCED FAT 3550 VARTY0026621.5% REDUCED FAT 3550 VARTY0026631% REDUCED FAT 3550 VARTY0026631% REDUCED FAT 3550 VARTY002675BORSETTI 3360 VARTY002705CRISP 4000 VARTY002705CRISP 4000 VARTY002705CRISP 4001 VARTY002734CRISPY CRUNCHY 4000 VARTY002742CRACKLING GOLDEN 4000 VARTY002784STEAM IN BAG 2622 VARTY002784STEAM IN BAG 2625 VARTY002784STEAM IN BAG 2625 VARTY002784STEAM IN BAG 2626 I expect the output to be VARTY 1% REDUCED FAT 002663 2 3550 VARTY 1.5% REDUCED FAT 002662 2 3550 VARTY 2% REDUCED FAT RC 002659 3 3590 VARTY BORSETTI 002675 1 3360 VARTY CRACKLING GOLDEN 002742 1 4000 VARTY CRISP 002705 3 4001 VARTY CRISPY CRUNCHY 002734 1 4000 VARTY DUTCHY 002639 1 4000 VARTY SACCHET 002660 1 3360 VARTY STEAM IN BAG 002784 4 2626 2622 2625 i am getting the count of VARTY002784 (how many times it had occured) and grouping the last columns to have unique values. But i got the output for my program as VARTY 1% REDUCED FAT 002663 2 3550 VARTY 1.5% REDUCED FAT 002662 2 3550 VARTY 2% REDUCED FAT RC 002659 3 3590 VARTY BORSETTI 002675 1 3360 VARTY CRACKLING GOLDEN 002742 1 4000 VARTY CRISP 002705 3 4001 VARTY CRISPY CRUNCHY 002734 1 4000 VARTY DUTCHY 002639 1 4000 VARTY SACCHET 002660 1 3360 VARTY STEAM IN BAG 002784 4 2626 Can any one help me? Regards Dhana |
|||
| Google UNIX.COM |