Sponsored Content
Full Discussion: Help to understand a script
Top Forums Shell Programming and Scripting Help to understand a script Post 302923533 by jose2802 on Monday 3rd of November 2014 12:40:48 PM
Old 11-03-2014
Help to understand a script

Hello world! Can someone please explain me how this code works? I'ts supposed to find words in a dictionary and show the anagrams of the words.

Code:
    {
    part = word2key($1)  
    data[part][$1] = $1  
}


function word2key(word,     a, i, x, result)
{
    x = split(word, a, "")
    asort(a)

    for (i = 1; i <= x; i++)
        result = result a[i]

    return result
}
END {
    sort = "sort"
    for (part in data) {
        nwords = asorti(data[part], words)
        if (nwords == 1)
            continue

        for (j = 1; j <= nwords; j++)
            printf("%s ", words[j]) | sort
        print "" | sort
    }
    close(sort)
}

 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

help wanted to understand MQ script

hi , i am writing a script to copy the MQ messages from onw queue to another. The following i got from one site, but i di not understand , can anyone explain. /root/scripts/sap/q -m$Q_MANAGER -i$Q_NAME_SRC_1 -F/logs/mq/MQ_COPYdump_$Q_NAME_SRC_1.$$ /root/scripts/sap/q -m$Q_MANAGER... (0 Replies)
Discussion started by: Satyak
0 Replies

2. Shell Programming and Scripting

Can't understand the script

I am relatively new to Shell Scripting. I can't understand the following two scripts. Can someone please spare a minute to explain? 1) content s of file a are (021) 654-1234 sed 's/(//g;s/)//g;s/ /-/g' a 021-654-1234 2)cut -d: -f1,3,7 /etc/passwd |sort -t: +1n gives error (3 Replies)
Discussion started by: shahdharmit
3 Replies

3. Shell Programming and Scripting

Help to understand the script

Hi All; Is there anybody can explain this script please? trap 'C_logmsg "F" "CNTL/c OS signal trapped, Script ${G_SCRIPTNAME] terminated"; exit 1' 2 trap 'C_logmsg "F" "Kill Job Event sent from the Console, Script ${G_SCRIPTNAME] terminated"; exit 1' 15 (3 Replies)
Discussion started by: thankbe
3 Replies

4. Shell Programming and Scripting

Need to understand the script pls help

Can u please explain what it is doing #!/bin/sh fullyear=`/home/local/bin/datemmdd 1`"."`date +%Y` uehist=/u05/home/celldba/utility/ue/prod/history echo $fullyear cd $uehist ls -ltr pwroutages.master.$fullyear* | awk '{print $9}' > /u01/home/celldba/tmp/pwroutages_master_all_tmp while... (2 Replies)
Discussion started by: raopatwari
2 Replies

5. Shell Programming and Scripting

Need help to understand ksh script

Hi All, I have a ksh script & would like to understand mening of below lines in script, Starting lines of script is as below, #!/bin/ksh #%W% %I% %D% %T% ---- ??? #%W%G --- ??? num_ctrl_files=0 OS=`uname` if then //g' | egrep -v '(.sh:|.ksh:)' | sed 's/^.*://g' | sed 's/^M//g' |... (6 Replies)
Discussion started by: gr8_usk
6 Replies

6. Shell Programming and Scripting

Understand script formte

Hi i have one script and i am running it but not getting current output so i want to understand how to input in the script. when i do help then i am getting below massage thanks got it (1 Reply)
Discussion started by: asavaliya
1 Replies

7. Shell Programming and Scripting

Can't understand script output

New to korn shel1 and having an issue. The following is suppose to read the parameter values from files in a source directory and then pass them on to a log file in a different directory, The ArchiveTracker scripts is suppose to call the parameterreader script to exact the parameter values and... (3 Replies)
Discussion started by: bayouprophet
3 Replies

8. Shell Programming and Scripting

Need help to understand the below shell script

Please help me to understand the below 3 lines of code.execute shell in jenkins 1)APP_IP=$( docker inspect --format '{{ .NetworkSettings.Networks.'"$DOCKER_NETWORK_NAME"'.IPAddress }}' ${PROJECT_NAME_KEY}"-CI" ) 2)HOST_WORKSPACE=$(echo ${WORKSPACE} | sed... (1 Reply)
Discussion started by: naresh85
1 Replies

9. UNIX for Beginners Questions & Answers

Help me understand this script

#!/bin/awk -f BEGIN {i=1;file="modified.txt"} { if ($0 !~ /^DS:/) {print $0 >> file} else { if ($0 ~ /^DS:/) {print "DS: ",i >> file;if (i==8) {i=1} else {i++}}; } } END {gzip file} Can someone explain to me how this above script works, I got it from a friend but not able... (3 Replies)
Discussion started by: Kamesh G
3 Replies
gnome-dictionary(1)					      General Commands Manual					       gnome-dictionary(1)

NAME
gnome-dictionary - Look up words on dictionaries SYNOPSIS
gnome-dictionary gnome-dictionary [options] or select Dictionary from the Accessories submenu of the Applications menu. DESCRIPTION
GNOME Dictionary provides dictionary definitions of words, using a dictionary source. For full documentation see the GNOME Dictionary online help. OPTIONS
--look-up word Looks up the specified word using the pre-defined dictionary source. -s source or --source source Uses the specified source for looking up words. This does not affect the global settings. -l or --list-sources Lists all the sources available. -n or --no-window Using this switch with the --look-up will print the definitions found on the console without launching the GUI. --help Display help information. CONFIGURATION
All the configuration is handled using GConf. AUTHOR
GNOME Dictionary was originally written by Spiros Papadimitriou (<spapadim+@cs.cmu.edu>), Mike Hughes (<mfh@psilord.com>) and Bradford Hov- inen (<hovinen@udel.edu>). Emmanuele Bassi (<ebassi@gmail.com>) rewrote it from scratch. This manual page was originally written by Jochen Voss <voss@mathematik.uni-kl.de>. SEE ALSO
dict(1), dictd(8), http://www.dict.org/, RFC 2229 gnome-utils 2.13.4 Jan 2 2005 gnome-dictionary(1)
All times are GMT -4. The time now is 09:23 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy