I think you already get the best advice possible in terms of implementation, so i will concentrate on the intrinsics of the problem:
Basically you have to parse a file, do a group change and reduce your input set by a set of key values. All these procedures/algorithms are basic tasks which you will have to handle on a daily basis in one or the other form in your future job. Probably this is why your professor designed the task this way.
Here is what a group change is and how it is carried out:
You have a file/table/datastructure with basically two columns: a "key" column and a "value" column. You sort that file for the key, then read it line by line and every time the key value changes you have to carry out some action.
For instance: Every customer of a business, instead of paying, will have written a record in a book (=file): his name and the value of the good he takes. At the end it looks like:
The task is to sum up the total for every customer and print a list with the totals. This is how it is done:
First sort the file for the key value, which is the first field in this case (the customer name):
Now read that file line by line. Store the last value of your key into a buffer. Optionally you might have an default action for every line, which be carried out here - in this case sum up the value. Whenever the key changes the comparison of the new key to the last key in this buffer will fail. Then you have to do your action (in this case print the total) and start over with the new key stored in the buffer. (Don't forget that at files end you have to end-process your last key value.)
Here is it in pseudo-code:
This is called a "single group change". There are also multiple group changes: suppose the customers would want a detailed statement, where the goods are sorted in groups and a subtotal should be given for every group of goods and a grand total for the customer (dual group change). It will need a second key field and i am sure you could write the pseudo code for this one already yourself.
I hope this helps in understanding.
(corollary: read carefully the man page of "awk", especially the part about how awk works and how "awk" scripts are formed. Does that ring a bell?)
Hi everyone,
I need a help on Unix scripting.
I have a file is like this
Date Amt
20071205 10
20071204 10
20071203 200
20071204 300
20071203 400
20071205 140
20071203 100
20071205 100... (1 Reply)
Hi All,
I have a file like -
num.txt
12, 34, 65, line1
34, 65, 89, line2
43, 65, 77, line3
I want to do two things -
1. Add first three columns of each line and print the line with largest value.
i.e. (12+34+65) for 1st line and so on.
2. Add middle column of each line i.e.... (3 Replies)
Basically I have to process a text file which has been sorted this way:
John 12
John 13
John 10
John 900
Peter 20
Peter 30
Peter 32
The first column is a name, and the second an arbitrary value, both delimited by a space. How can I sum them up such that it would become:
John 935... (2 Replies)
Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
1. The problem statement, all variables and given/known data:
Hi guys, i'm a new guy here, and it's my first time creating a unix script.
can you guys help me out here? i'd... (3 Replies)
a,b,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,aa,bb,cc,dd,ee,ff,gg,hh,ii
a thru ii are digits and strings....
The awk needed....if coloumn 9 == i (coloumn 9 is string ), output the sum of x's(coloumn 22 ) in all records and sum of y's (coloumn 23 ) in all records in a file (records.txt).... (6 Replies)
Can anyone tell me how sum values in each record of a file and append that value to the end? For instance a typical record will be:
FY12,Budget,771100,,,,,,,,,250,-250
I'd like the record to become
FY12,Budget,771100,,,,,,,,,250,-250,0
which can be put into another file.
Thank you. (6 Replies)
I have a file with the following format
AAAAA 1.34B 0.76B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.00B 0.90B 0.00B 0.00B 0.46B 0.00B 0.03B 0.00B ... (4 Replies)
Hello,
I am facing issue in summing up a column in unix.I am displaying a column sum up to 4 decimal places and below is the code snippet
sed '1d' abc.csv | cut -d',' -f7 | awk '{s+=$1}END{ printf("%.4f\n",s)}'
-170552450514.8603
example of data values in the column(not... (3 Replies)
Discussion started by: karthik adiga
3 Replies
LEARN ABOUT PHP
nsapi_virtual
NSAPI_VIRTUAL(3) 1 NSAPI_VIRTUAL(3)nsapi_virtual - Perform an NSAPI sub-requestSYNOPSIS
bool nsapi_virtual (string $uri)
DESCRIPTION nsapi_virtual(3) is an NSAPI-specific function which is equivalent to <!--#include virtual...--> in SSI ( .shtml files). It does an NSAPI
sub-request. It is useful for including CGI scripts or .shtml files, or anything else that you'd parse through webserver.
To run the sub-request, all buffers are terminated and flushed to the browser, pending headers are sent too.
You cannot make recursive requests with this function to other PHP scripts. If you want to include PHP scripts, use include(3) or
require(3).
Note
This function depends on a undocumented feature of the Netscape/iPlanet/Sun webservers. Use phpinfo(3) to determine if it is avail-
able. In the Unix environment it should always work, in Windows it depends on the name of a ns-httpdXX.dll file.
Read the note about subrequests in the NSAPI section (UNIX, Windows) if you experience this problem.
PARAMETERS
o $uri
- The URI of the script.
RETURN VALUES
Returns TRUE on success or FALSE on failure.
PHP Documentation Group NSAPI_VIRTUAL(3)