find and group records in a file


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users find and group records in a file
# 15  
Old 04-18-2007
Wow Wow Wow!!!!!!!!
I Couldnt Say Anything... Awesome...
U R A Real Genius... Great And Thanks A Ton...
This Was Bugging Me For Last 3 Days... Great Relief... Thanks A Million :d
# 16  
Old 04-19-2007
Hi Vgersh,

This command is working perfect in command line.

when i m using this code it gives an error "
awk: sum is not an array"

Can u please help. Sorry to bother you again. Thanks a lot!!

WORKING_DIR="/opt/apps/manu/custcpfr/temp/perl_poc"
OUTPUT_FILENAME="temp.dat"

ctlfile="test.ctl"
AGGR_VALUE=`grep ^AGGREGATE $ctlfile`

AGGREGATE=`echo $AGGR_VALUE | cut -f2 -d "=" | sed -e 's/^ //g'`

echo $AGGREGATE

if [ $AGGREGATE = "YES" ]
then
echo "Right"
fi

if [ $AGGREGATE = "YES" ]
then
`awk -F"|" '{ idx=$2 FS $3 FS $4 FS $5; sum[idx] += $7; first[idx]=$1;sixth[idx]=$6 } END { for (record in sum) printf("%s%s%s%s%s%s%s\n", first[record], FS, record, FS, sixth[idx], FS, sum[record]) }' $WORKING_DIR/$OUTPUT_FILENAME > $WORKING_DIR/$OUTPUT_FILENAME`

fi
# 17  
Old 04-19-2007
sixth[name] and not sixth[idx].. sorry.. but still not working Smilie
# 18  
Old 04-19-2007
Quote:
Originally Posted by mike_ap2006
Hi Vgersh,

This command is working perfect in command line.

when i m using this code it gives an error "
awk: sum is not an array"

Can u please help. Sorry to bother you again. Thanks a lot!!

WORKING_DIR="/opt/apps/manu/custcpfr/temp/perl_poc"
OUTPUT_FILENAME="temp.dat"

ctlfile="test.ctl"
AGGR_VALUE=`grep ^AGGREGATE $ctlfile`

AGGREGATE=`echo $AGGR_VALUE | cut -f2 -d "=" | sed -e 's/^ //g'`

echo $AGGREGATE

if [ $AGGREGATE = "YES" ]
then
echo "Right"
fi

if [ $AGGREGATE = "YES" ]
then
`awk -F"|" '{ idx=$2 FS $3 FS $4 FS $5; sum[idx] += $7; first[idx]=$1;sixth[idx]=$6 } END { for (record in sum) printf("%s%s%s%s%s%s%s\n", first[record], FS, record, FS, sixth[idx], FS, sum[record]) }' $WORKING_DIR/$OUTPUT_FILENAME > $WORKING_DIR/$OUTPUT_FILENAME`

fi
Use
awk -F"|" '{ idx=$2 FS $3 FS $4 FS $5; sum[idx] += $7; first[idx]=$1;sixth[idx]=$6 } END { for (record in sum) printf("%s%s%s%s%s%s%s\n", first[record], FS, record, FS, sixth[idx], FS, sum[record]) }' $WORKING_DIR/$OUTPUT_FILENAME > $WORKING_DIR/$OUTPUT_FILENAME

without the "`".
# 19  
Old 04-19-2007
I tried them...Still not working.
# 20  
Old 04-19-2007
mike, code tags exist for a reason.

Dumping a bunch of code in a post without them is pointless, nobody will want to read you posts, and few will bother to try.
# 21  
Old 04-19-2007
Hi I got it fixed.

As i m redirecting to the same file it was not working.
So i used outfile to get the result and used a mv command

awk -F"|" '{ idx=$2 FS $3 FS $4 FS $5; sum[idx] += $7; first[idx]=$1;sixth[idx]=$6 } END { for (record in sum) printf("%s%s%s%s%s%s%s\n", first[record], FS, record, FS, sixth[idx], FS, sum[record]) }' $WORKING_DIR/$OUTPUT_FILENAME > out
mv out $WORKING_DIR/$OUTPUT_FILENAME

Thanks for your help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

To group records in the file in UNIX

Hi All, I am using RHEL 6.9. I got a requirement to group the records in a file.The file content as shown below. #### FAILED JOBS IN XXX ##### 1> ABCD failed in the project XXX 2> HJK Job is in compiled state in the project XXX 3> ILKD failed in the project XXX 4> DFG failed in the... (5 Replies)
Discussion started by: ginrkf
5 Replies

2. Shell Programming and Scripting

Script to find blank records in a file except for few columns

I have a file with the following format: X|High|2|GIC|DM||XHM|||6 Months X|Moderate|2|GIC|DM||XHM|||6 Months X|High|2|GCM|DM||XSF|||6 Months X|Med|2|GCM|DM||XSF|||6 Here there are ten columns but I need to print rows having blank records in any of the rows (except for 6th,8th and 9th... (10 Replies)
Discussion started by: chatwithsaurav
10 Replies

3. UNIX for Dummies Questions & Answers

Find a file in group of jars

Hi, jar -tvf tools.jar | grep LinkInfoImpl Output: 4968 Fri Feb 22 02:34:52 EST 2008 com/sun/tools/doclets/formats/html/LinkInfoImpl.class However, i need the similar output for all jar files under /apps/lib/ directory and its subdirectories. Can you please help format my command to... (3 Replies)
Discussion started by: mohtashims
3 Replies

4. UNIX for Dummies Questions & Answers

CSV file:Find duplicates, save original and duplicate records in a new file

Hi Unix gurus, Maybe it is too much to ask for but please take a moment and help me out. A very humble request to you gurus. I'm new to Unix and I have started learning Unix. I have this project which is way to advanced for me. File format: CSV file File has four columns with no header... (8 Replies)
Discussion started by: arvindosu
8 Replies

5. UNIX for Dummies Questions & Answers

How to find particular records in a file?

Hi all, i have one file contains 20 records 1 2 - - - 20 i want to find 5th records and 8th records and 14th plz tell me which command use? Thanks to advance (4 Replies)
Discussion started by: venkatreddy
4 Replies

6. Shell Programming and Scripting

Find Duplicate records in first Column in File

Hi, Need to find a duplicate records on the first column, ANU4501710430989 0000000W20389390 ANU4501710430989 0000000W67065483 ANU4501130050520 0000000W80838713 ANU4501210170685 0000000W69246611... (3 Replies)
Discussion started by: Murugesh
3 Replies

7. Shell Programming and Scripting

how to group records in a file

hi, I have records like this D127@dm.com,127,569,BRAD,25/08/2009 23:59 D127@dm.com,127,569,BRAD,25/08/2009 23:59 D159@dm.com,159,1170,DAVE,25/08/2009 23:59 D159@dm.com,159,1181,HALE,25/08/2009 23:59 D393@dm.com,393,1209,CAPIT,25/08/2009 23:59 D457@dm.com,457,571,NORTT,25/08/2009 23:59... (4 Replies)
Discussion started by: trichyselva
4 Replies

8. Shell Programming and Scripting

KSH to group records in a file and compare it with another file

Hi, I've a file like below: DeptFile.csv DeptID EmpID ------- ------ Dep01 Emp01 Dep01 Emp02 Dep01 Emp03 Dep02 Emp04 Dep02 Emp05 I've another file which has EmpFile.csv EmpID Salary ------ ------ (3 Replies)
Discussion started by: Matrix2682
3 Replies

9. Shell Programming and Scripting

find out duplicate records in file?

Dear All, I have one file which looks like : account1:passwd1 account2:passwd2 account3:passwd3 account1:passwd4 account5:passwd5 account6:passwd6 you can see there're two records for account1. and is there any shell command which can find out : account1 is the duplicate record in... (3 Replies)
Discussion started by: tiger2000
3 Replies

10. Shell Programming and Scripting

How to find Duplicate Records in a text file

Hi all pls help me by providing soln for my problem I'm having a text file which contains duplicate records . Example: abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 abc 1000 3452 2463 2343 2176 7654 3452 8765 5643 3452 tas 3420 3562 ... (1 Reply)
Discussion started by: G.Aavudai
1 Replies
Login or Register to Ask a Question