Sponsored Content
Top Forums Shell Programming and Scripting Script to compact information ! Post 302368476 by summer_cherry on Thursday 5th of November 2009 01:40:07 AM
Old 11-05-2009
Code:
while(<DATA>){
	my @tmp = split(",",$_);
	my $key = $tmp[0].",D,".$tmp[2];
	$hash{$key}->{open}=$tmp[4] if $hash{$key}->{open}=="";
	$hash{$key}->{low}=$tmp[6] if $hash{$key}->{low}=="";
	$hash{$key}->{high}=($hash{$key}->{high}<$tmp[5])?$tmp[5]:$hash{$key}->{high};
	$hash{$key}->{low}=($hash{$key}->{low}>$tmp[6])?$tmp[6]:$hash{$key}->{low};
	$hash{$key}->{close}=$tmp[7];
	$hash{$key}->{vol}+=$tmp[8];
}
foreach my $key(keys %hash){
	print $key,",",$hash{$key}->{open},",",$hash{$key}->{high},",",$hash{$key}->{low},",",$hash{$key}->{close},",",$hash{$key}->{vol},"\n";
}
__DATA__
EUR_USD,I,11/02/2009,12:00,1.4783,1.4784,1.4766,1.4774,824
EUR_USD,I,11/02/2009,13:00,1.4773,1.4775,1.4746,1.4754,854
EUR_USD,I,11/02/2009,14:00,1.4753,1.4779,1.4739,1.4777,1320
EUR_USD,I,11/02/2009,15:00,1.4778,1.4844,1.4778,1.4817,2389
EUR_USD,I,11/02/2009,16:00,1.4816,1.4834,1.4813,1.4827,1302
EUR_USD,I,11/02/2009,17:00,1.4828,1.4831,1.4761,1.4762,1053
EUR_USD,I,11/02/2009,18:00,1.4761,1.4778,1.4731,1.4733,1148
EUR_USD,I,11/02/2009,19:00,1.4734,1.4771,1.4727,1.4751,1112
EUR_USD,I,11/02/2009,20:00,1.4752,1.4770,1.4747,1.4765,936
EUR_USD,I,11/02/2009,21:00,1.4764,1.4775,1.4763,1.4773,296
EUR_USD,I,11/02/2009,22:00,1.4772,1.4774,1.4760,1.4772,219
EUR_USD,I,11/02/2009,23:00,1.4773,1.4778,1.4769,1.4772,180
EUR_USD,I,11/03/2009,12:00,1.4635,1.4659,1.4631,1.4654,1207
EUR_USD,I,11/03/2009,13:00,1.4655,1.4668,1.4643,1.4651,1219
EUR_USD,I,11/03/2009,14:00,1.4652,1.4662,1.4633,1.4657,1690
EUR_USD,I,11/03/2009,15:00,1.4658,1.4696,1.4642,1.4676,2365
EUR_USD,I,11/03/2009,16:00,1.4675,1.4681,1.4631,1.4655,1592
EUR_USD,I,11/03/2009,17:00,1.4656,1.4695,1.4645,1.4685,1104
EUR_USD,I,11/03/2009,18:00,1.4686,1.4710,1.4678,1.4709,1006
EUR_USD,I,11/03/2009,19:00,1.4710,1.4732,1.4702,1.4702,988
EUR_USD,I,11/03/2009,20:00,1.4701,1.4722,1.4700,1.4711,723
EUR_USD,I,11/03/2009,21:00,1.4710,1.4732,1.4710,1.4721,371
EUR_USD,I,11/03/2009,22:00,1.4721,1.4727,1.4706,1.4716,395
EUR_USD,I,11/03/2009,23:00,1.4717,1.4732,1.4715,1.4731,227

 

6 More Discussions You Might Find Interesting

1. Windows & DOS: Issues & Discussions

formatting a Compact Flash in DOS format

:confused: I tryied to use the mount Command (and the msdos.utils) in Darwin 1.4 (OS X) to format a Compact Flash in DOS Format (I had already this native format but I changed it with Disk Utility in MacOS standard and the PC Card slot of a Windows 98-Laptop can't nore read the card) I want to... (1 Reply)
Discussion started by: dreamsurfer
1 Replies

2. Linux

How to Burn .gp Oracle 9.2.0.4.0 to Compact Disc Media on Windows Box

Hi All, I Downloaded Oracle 9.2.0.4.0 for Linux AS 4 and the file format is Directions to extract the files 1. Run "gunzip <filename>" on all the files. Eg. ship_9204_linux_disk1.cpio.gz 2. Extract the cpio archives with the command "cpio -idmv < <filename>" Eg. cpio -idmv... (0 Replies)
Discussion started by: prakashpichika
0 Replies

3. UNIX for Dummies Questions & Answers

User information script

Hi Guys, I just started learning unix and was wondering if anyone can assist me with my User info script.The script file lets the user input their personal information (Their name, address, phone number etc...). The script will then ask the user to input the info again if the input is incorrect... (2 Replies)
Discussion started by: rc1138
2 Replies

4. Shell Programming and Scripting

Compact 3-D output from a big input like:

Hi Experts!!!! Tried a lot but in vein,no success, please help to achieve this LOGIC behind is first field is reffrance row field, the second field shoud be made titles of coulmn and the the third field is made as matrix value. And if they dont match the matrix value should be 0. (Unix (Shell,... (1 Reply)
Discussion started by: ashis.tewari
1 Replies

5. Ubuntu

Format a compact flash card in Ubuntu

I need some assistance formatting a compact flash card in Ubtunu. I connect up the CF card through a USB reader. Ubuntu recognizes the reader usb device, but does not "mount" the CF card as a device. The CF card was formatted in FAT32 format. Any help would be greatly appreciated.... (3 Replies)
Discussion started by: genesis211
3 Replies

6. Shell Programming and Scripting

Compact script with array - Good idea?

Hi, I have a shell script where a lot of the code is repeated. I wanted to make the code much more compact so I spoke to a guy and he suggested using arrays, like follows: #!/bin/bash readonly -a nginx=('nginx' '--prefix=/opt' '-j 4' 'http://nginx.org/download/nginx-1.2.2.tar.gz' )... (2 Replies)
Discussion started by: Spadez
2 Replies
HASHSTASH(3)						 libbash hashstash Library Manual					      HASHSTASH(3)

NAME
hashstash -- libbash library that implements hash data structure SYNOPSIS
hashSet <Value> <Key> <HashName> [SubHashName [...]] $retval hashGet <Key> <HashName> [SubHashName [...]] $retval hashKeys <HashName> [SubHashName [...]] hashRemove <Key> <HashName> [SubHashName [...]] hashDelete <HashName> [SubHashName [...]] DESCRIPTION
General hashstash is a collection of functions that implement basic hash data-structure in bash scripting language. The function list: hashSet Adds a value to the hash hashGet Returns a value from the hash hashKeys Returns a list of keys of the hash hashRemove Removes a key from the hash hashDelete Deletes a hash Detailed interface description follows. FUNCTIONS DESCRIPTIONS
hashSet <Value> <Key> <Hashname> [SubHashName [...]] Adds a value to the hash. Parameters: <Value> The value to set in HashName[Key]. <Key> The key for the value Value. <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. Value will be the value of the key Key in the hash HashName. For example if you have (or want to define) hash C, which is subhash of hash B, which is subhash of hash A, and C has a key named ckey1 with value cval1, then you should use: hashSet cval1 ckey1 A B C $retval hashGet <Key> <HashName> [SubHashName [...]] Returns the value of Key in HashName to the $retval variable. Parameters: <Key> The key that hold the value we wish to get. <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. Return Value: The value of the key Key in the hash HashName. The value is returned in the variable $retval. $retval hashKeys <HashName> [SubHashName [...]] Returns a list of keys of the hash HashName in the variable $retval. Parameters: <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. Return Value: The value of the key Key in the hash HashName. The value is returned in the variable $retval. hashRemove <Key> <HashName> [SubHashName [...]] Removes the key Key from the hash HashName. <Key> The key we wish to remove from HashName. <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. This function should also be used to remove a sub-hash from its "father hash". In that case, the key will be the name of the sub-hash. hashDelete <HashName> [SubHashName [...]] Deletes the hash HashName [SubHashName [...]]. Parameters: <HashName> [SubHashName [...]] A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name. If this function is used on a sub-hash, a key with the name of the sub-hash will remain in its "father hash" and will hold a NULL value. BUGS
A hash name can only contain characters that are valid as part of bash variable names (i.e. a-zA-Z0-9_). The same applies for hash keys. As for now, there is no way of knowing if a key represents a value or a sub-hash. If a sub-hash will be used as a key, the returned value will be its keys list. EXAMPLES
Define hash table hashA with key Akey1 with value Aval1 use: % hashSet Aval1 Akey1 Ahash Now: % hashGet Akey1 Ahash % echo $retval Aval1 % hashKeys Ahash % echo $retval Akey1 % HISTORY
The idea to write hashstash library appeared when we've discovered the full power of the bash eval function. As of the name hashstash, it has two meanings. The first, it means 'stash' of hash functions. The second is, that hashstash contains sub- hashes inside, so it looks like stash of packed information. AUTHORS
Hai Zaar <haizaar@haizaar.com> Gil Ran <gil@ran4.net> SEE ALSO
ldbash(1), libbash(1) Linux Epoch Linux
All times are GMT -4. The time now is 01:06 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy