The UNIX and Linux Forums  

Go Back   UNIX e Linux Forum > Inizio Forum > Shell scripting e di programmazione
.
google unix.com



Shell scripting e di programmazione Pubblica domande su KSH, CSH, SH, Bash, Perl, PHP, sed, awk e da altri script di shell e linguaggi di scripting shell qui.

Più di UNIX e Linux Forum Argomenti potreste trovare utili
Filo Thread Starter Forum Risposte Ultimo Post
Località sensibili funzione hash Basato su concomitanza Rand Ordine Statistiche iBot UNIX e Linux RSS News 0 07-07-2008 06:10 AM
Passando variabile globale di una funzione che è chiamato da un'altra funzione sars Shell scripting e di programmazione 4 06-30-2008 12:39 PM
Perl Hash Harikrishna Shell scripting e di programmazione 1 06-03-2008 12:45 AM
Hash MD5 calcolo zedex Di programmazione ad alto livello 4 02-24-2007 02:37 AM
Hash (#) come una variabile errolg UNIX for Dummies Domande & Risposte 5 05-21-2002 04:03 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Cerca in questo Thread Rate Thread Modalità di visualizzazione
  #1 (permalink)  
Old 07-16-2008
dinjo_jo dinjo_jo is offline
Utente Registrato
  
 

Iscriviti Data: maggio 2008
Interventi: 78
Awk funzione hash.

Ho un file con un formato di

A, 2
B, 2
G, 3
A, 2
A, 3
A, 2
D, 7
A, 2
E, 2
A, 2

Ho bisogno di creare una somma di ogni alfabeto con i numeri assegnati ai utilizzando awk.
  #2 (permalink)  
Old 07-16-2008
Tytalus's Avatar
Tytalus Tytalus is offline Forum Advisor  
echo (1 .. 9) ^ 2 \; | bc
  
 

Iscriviti Data: giugno 2003
Localizzazione: Scozia
Interventi: 431

Codice:
#  awk -F"," '{cnt[$1]+=$2}END{for (x in cnt){print x,cnt[x]}}' infile
A 13
B 2
D 7
E 2
G 3

  #3 (permalink)  
Old 07-16-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Utente Registrato
  
 

Iscriviti Data: dicembre 2007
Località: Virginia, Stati Uniti d'America.
Interventi: 251
Volevi un algoritmo pseudo hash e di controllo in base al contenuto in linea o un semplice
somma delle occorrenze (già previsto in precedenza)?
Ecco la prima.

Codice:
 
function makesimplehash(data,seedval, n,x,hashval,store,p) {

                 for (n = 1 ; data[n] != 0 ; n++) {
                     x = sprintf("%d",data[n])
                     if (x == 0) {
                                 gencharsarr(store)
                                 for (p=0 ; p < 10 ; p++) {
                                     if (store[p] == data[n]) {x = p + 1; break;}
                                 }
                     }
                     #printf "Derived value %d from %d\n",x,data[n]
                     hashval += int(x + seedval % (n + 1))
                 }
                 return hashval
}         

function zeroarr(data,nv, x) {
                while (x < nv) {data[x] = 0; x++}
}

function gencharsarr(data, n) {
str="abcdefghijk"
                    for (n=0 ; n < 10 ; n++) {data[n]=substr(str,n,1)}
}

function createhashable(szl, store,str,vn) {
store[0]=""
                        gencharsarr(store)
                        for (vn=0 ; vn < szl + 1; vn++) {
                            if (vn == 0) {str = store[int(1 + rand() * 9)]; continue}
                            str = str "," int(1 + rand() * 10)
                        }
                        return str
} 
                           

BEGIN {
arra[0]=""
cnt=0;sz=0
       if (ARGC == 2 && ARGV[1] == "-generate") {
          srand()
          while (cnt < 20) {
                sz = int(1 + rand() * 7)
                print createhashable(sz)
                cnt++
          }
          exit
        }
}

{ 
FS=","
         
         if ( (num = split($0,arra)) == 0) {printf "At record number %d, malformed field content.\n",NR ; next}
         arra[num + 1] = 0;
         #for (a = 1 ; a <= num ; a++) {print a,arra[a]}
         printf "Hash value for %s = %d.\n",$0,makesimplehash(arra,15003)
         zeroarr(arra,num)
}

Closed Thread

Segnalibri

Thread Tools Cerca in questo Thread
Cerca in questo Thread:

Ricerca Avanzata
Modalità di visualizzazione Vota questo thread
Vota questo thread:

Distacco regolamento
Tu non può post nuovo thread
Tu non può inviare una risposta
Tu non può postare allegati
Tu non può modificare i tuoi post

BB codice è Su
Smilies sono Su
[IMG] codice Su
Codice HTML è Chiuso
Trackbacks sono Su
Pingbacks sono Su
Refbacks sono Su




Tutti gli orari sono GMT -4. La data di oggi è 06:29 PM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Traduzioni Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
UNIX e Linux Forum Content Copyright © 1993-2009. Tutti i diritti Reserved.Ad di gestione da RedTyger

Contenuti pertinenti URL da vBSEO 3.2.0