Subtotal in UNIX


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Subtotal in UNIX
# 1  
Old 05-15-2014
Question Subtotal in UNIX

Please help me on below req

Data in file

ARIZONA HCPAZ 47
ARIZONA HCPAZCONT 3056
ARIZONA AZA 20
CALIFORNIA HC06 878
CALIFORNIA LC04 51
CALIFORNIA LC06 4039
CALIFORNIA HCPCACONT 4960
THE CAMDEN GROUP CAM 83
TO BE DETERMINED TBD 3
TO BE DETERMINED 8-J 0
TO BE DETERMINED AS0 0


output I need:

ARIZONA HCPAZ 47
ARIZONA HCPAZCONT 3056
ARIZONA AZA 20

ARIZONA_SUB_TOTAL : 3,123



CALIFORNIA HC06 878
CALIFORNIA LC04 51
CALIFORNIA LC06 4039
CALIFORNIA HCPCACONT 4960

CALIFORNIA_SUB_TOTAL : 9,928



THE CAMDEN GROUP CAM 83
TO BE DETERMINED TBD 3
TO BE DETERMINED 8-J 0
TO BE DETERMINED AS0 0

OTHER_SUB_TOTAL :86


Thanks in advance
# 2  
Old 05-15-2014
We are here to help you, not to do your work for you. What have you tried?

You did a poor job of explaining your data. For example, how do you decide what is "OTHER"?

Finally, use code tags for code and data samples.

Regards,
Alister
# 3  
Old 05-15-2014
What is the delimiter? If it is space delimited and you have spaces in the first field, then you won't be able to properly parse the file. You should use either : or ~ to delimit the fields. If you change the delimiter you can probably use cut such as

for line in `cat data.dat`
do
echo "column 1: "+`echo ${line} | cut -d":" | -f1`
echo "column 2: "+`echo ${line} | cut -d":" | -f2`
echo "column 3: "+`echo ${line} | cut -d":" | -f3`
done

I have not yet run the above code to check for bugs.
You will need to take the logic and change it for what you need.
# 4  
Old 05-15-2014
if it is not california and arizona then it its others
# 5  
Old 05-15-2014
Quote:
Originally Posted by skchevva
if it is not california and arizona then it its others
But you still need to know where the second and third fields are. You might be able to do a for loop, check for CA and AZ first with a case statement and have the else be grab the last word for the third column and the second to last word for the second column and hard code other for the first column.
# 6  
Old 05-15-2014
it is comma deleimter
# 7  
Old 05-15-2014
There is not a single comma in your sample input data.

Please stop using icode for everything you type. Use code only for code and data.

I recommend that you start over with data that actually reflects what you're telling us.

And, finally, what have you tried to solve the problem?

Regards,
Alister
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to add subtotal and total according 3rd field mentioned below table?

111AKKK|SHA|20|25 111|AKKK|SHA|15|35 112|ABC|FL|25|45 112|ABC|FL|15|15 115|AKKK|ASH|10|15 115|AKKK|ASH|20|20 112|ABC|FL|25|20 115|AKKK|ASH|30|35 111|AKKK|SHA|10|45 112|ABC|KL|15|15 112|ABC|KL|20|25 115|AKKK|ASH|30|35 please write a shell script output should be below mentioned... (26 Replies)
Discussion started by: udhal
26 Replies

2. Shell Programming and Scripting

File Transfer from Window server to UNIX and UNIX to UNIX

Dear All, Can someone help to command or program to transfer the file from windows to Unix server and from one unix server to another Unix server in secure way. I would request no samba client. (4 Replies)
Discussion started by: yadavricky
4 Replies

3. UNIX for Dummies Questions & Answers

How does unix system administration, unix programming, unix network programming differ?

How does unix system administration, unix programming, unix network programming differ? Please help. (0 Replies)
Discussion started by: thulasidharan2k
0 Replies

4. UNIX for Dummies Questions & Answers

How do you subtotal lines in a file? Awk?

I have a file with 8 fields. I need the subtotals for fields 7 & 8 when field 5 changes. cat wk1 01/02/2011/18AB/17/18/000000071/000000033 01/02/2011/18AB/17/18/000000164/000000021 01/02/2011/18AB/17/18/000000109/000000023 01/02/2011/28FB/04/04/000000000/000000000... (2 Replies)
Discussion started by: MS75001
2 Replies

5. Shell Programming and Scripting

Batch job in unix server to move the pdf file from unix to windows.

Hi Experts, I have a requirement where i need to setup a batch job which runs everymonth and move the pdf files from unix server to windows servers. Could some body provide the inputs for this. and also please provide the inputs on how to map the network dirve in the unix like that... (1 Reply)
Discussion started by: ger199901
1 Replies

6. Shell Programming and Scripting

subtotal columns

Hello I have a file that has two (or more) different types of records I want to total. How would I do this using awk? The file may contain several dozen records. The records are sorted on the database column - what I want to do is get the amount of space that each table has in that database... (5 Replies)
Discussion started by: stonemonolith
5 Replies

7. Shell Programming and Scripting

FTP script for sending a file from one unix directory to another unix server director

Hi, My local server is :/usr/abcd/ Remote server is :/Usr/host/test/ I want to send files from local unix directory(All files starting with O_999) to remote host unix directory. Can any body give me the Unix Shell script to do this. One more doubt: Shall we need to change the file... (1 Reply)
Discussion started by: raja_1234
1 Replies

8. UNIX for Advanced & Expert Users

missing Path(in UNIX) when i launch a job on to unix machine using windows SSh

hi i want run an unix application from a windows program/application.i am using SSH(command line version)to log on to a unix machine from windows. the application has to read a configuration file inorder to run. the configuration file .CFG is in bin in my home directory. but the application... (1 Reply)
Discussion started by: megastar
1 Replies

9. UNIX for Dummies Questions & Answers

UNIX problem? Unix programm runs windows 2000 CPU over 100%

Okee problems...!! What is happening: Unix server with some programms, workstations are windows 2000, the workstations work good but when you start a programm on the Unix server the CPU of the workstations go to 100% usage resulting that the system gets very slow. The programm well its running so... (2 Replies)
Discussion started by: zerocool
2 Replies
Login or Register to Ask a Question