BASH, HASH and AWK


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers BASH, HASH and AWK
# 1  
Old 12-09-2008
BASH, HASH and AWK

Hi,

I am working on this idea that I want to process some information from a command dump.

Using the dump I will search for a string. If it finds the string, it must post a
different/associated string to output/logfile.
Example:
'Find "cookie jar"' then 'echo "carpool/tomorrow" > logfile'

It does not stop with 1 string to search for, it will have around 100 different
strings to search for, and everyone have some other content assigned to it, thus it
should be some clever loop.
I COULD have written one grep for each value, but since it is growing by the day,
I find that a waste of lines and bytes.

To prevent an infinite loop, it should remove what it has already found from the
sourcelist of what to search for or somehow mark it as processed.
(The sourcelist is overwritten each time the PC boots with an updated one)

The tricky bit for me is both how I can arrange it with a HASH table, I've done
something similar in PERL, but in BASH/AWK I am unable to do this. The system is very
limited and its not permitted toexpand on its available apps by any byte atm.

I've drawn out how I think the design is going to work.

In itself, there are several commands it will search the output for, but I am used to
having a launch script, that then uses a "core search" script with the variables that
designs it to that and that output file, predefined variables file and logfile.
It gives control and scalabillity ;-)

(The pink area is where the core script loops in itself to search for every available word)

Is this hard to acomplish?
I've written some BASH scripts in the past, aswell as some BATCH and PERL scripts,
though nothing close to this complexity.
BASH, HASH and AWK-hwscriptpng
# 2  
Old 12-10-2008
What I really need help with, is a script that searches for a changable string, if it finds it, we replace the output with the corresponding value/string.

say if I have a datafile with this info(string to search for separated by a , with the output after it):

Code:
data searchable string, this is for the output to be posted
another searchable string, this is yet again for the output to be posted.
third wonder searchable, this is another output string

It would without a hitch with either ; or = or any other sign to separate the two, just so if the first is found, the second is posted.

Any ideas? :-)
# 3  
Old 02-13-2009
> The tricky bit for me is both how I can arrange it with a HASH table, I've done
> something similar in PERL, but in BASH/AWK I am unable to do this.

Might not be exactly what you're looking for but...

With regards to above, you could try this: Creating associative or hash arrays in bash using sed and strings without the use of arrays, looping and conditionals.
You'll have to tweak that code for your tastes though to use different delimeters depending on what's appropriate to you.

Regards,
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need to print hash of hash in table format

Hi, I have a hash of hash where it has name, activities and count i have data like this - $result->{$name}->{$activities} = $value; content of that are - name - robert tom cat peter activities - running, eating, sleeping , drinking, work i need to print output as below ... (3 Replies)
Discussion started by: asak
3 Replies

2. Shell Programming and Scripting

awk command hash array not printing

I'm new to awk command. The HASH ARRAY is not printing. Merging 2 files togather. vault_input.txt 3P04_Dep_Inxml:2230 REM02_Dep_Inxml:2200 REM03_Dep_Inxml:2400 REM05:2200 REM06:2200 tst6.txt Nov:10:2115:3P04_Dep_Inxml Nov:10:2129:REM02_Dep_Inxml Nov:10:2235:REM03_Dep_Inxml... (5 Replies)
Discussion started by: Sanj123
5 Replies

3. UNIX for Dummies Questions & Answers

Help in awk/bash

Hi, I am also a newbie in awk and trying to find solution of my problem. I have one reference file 1.txt with 2 columns and I want to search other 10 files (a.txt, b.txt......h.txt each with 5 columns) corresponding to the values of 2nd column from 1.txt. If the value from 2nd column from 1.txt... (0 Replies)
Discussion started by: bioinfo
0 Replies

4. Shell Programming and Scripting

Dynamically parse BibTeX and create hash of hash

Hello gurus, Iam trying to parse following BibTex file (bibliography.bib): @book{Lee2000a, abstract = {Abstract goes here}, author = {Lee, Wenke and Stolfo, Salvatore J}, title = {{Data mining approaches for intrusion detection}}, year = {2000} } @article{Forrest1996, abstract =... (0 Replies)
Discussion started by: wakatana
0 Replies

5. Shell Programming and Scripting

Compare values of hashes of hash for n number of hash in perl without sorting.

Hi, I have an hashes of hash, where hash is dynamic, it can be n number of hash. i need to compare data_count values of all . my %result ( $abc => { 'data_count' => '10', 'ID' => 'ABC122', } $def => { 'data_count' => '20', 'ID' => 'defASe', ... (1 Reply)
Discussion started by: asak
1 Replies

6. Shell Programming and Scripting

perl hash - using a range as a hash key.

Hi, In Perl, is it possible to use a range of numbers with '..' as a key in a hash? Something in like: %hash = ( '768..1536' => '1G', '1537..2560' => '2G' ); That is, the range operation is evaluated, and all members of the range are... (3 Replies)
Discussion started by: dsw
3 Replies

7. Shell Programming and Scripting

Perl Hash:Can not keep hash data in the same order that it was inserted

Can Someone explain me why even using Tie::IxHash I can not get the output data in the same order that it was inserted? See code below. #!/usr/bin/perl use warnings; use Tie::IxHash; use strict; tie (my %programs, "Tie::IxHash"); while (my $line = <DATA>) { chomp $line; my(... (1 Reply)
Discussion started by: jgfcoimbra
1 Replies

8. Shell Programming and Scripting

Assigning a hash to another hash key

Hello, I have a hash in hsh. I need to assign it to another hash globalHsh. I think the below statement does not work $globalHsh{$id} = %hsh; What is the right way to assign it? Thanks (3 Replies)
Discussion started by: rsanjay
3 Replies

9. Shell Programming and Scripting

Print Entire hash list (hash of hashes)

I have a script with dynamic hash of hashes , and I want to print the entire hash (with all other hashes). Itried to do it recursively by checking if the current key is a hash and if yes call the current function again with refference to the sub hash. Most of the printing seems to be OK but in... (1 Reply)
Discussion started by: Alalush
1 Replies

10. Shell Programming and Scripting

Awk Hash Function.

I have a file with a format of A,2 B,2 G,3 A,2 A,3 A,2 D,7 A,2 E,2 A,2 I need to create a sum of each alphabet with the numbers assigned to it using awk. (2 Replies)
Discussion started by: dinjo_jo
2 Replies
Login or Register to Ask a Question