11-27-2007
My code:
#!/usr/bin/awk -f
function swapa(arr,i,j, tmp) {
tmp=arr[i];
arr[i]=arr[j];
arr[j]=tmp;
}
function _qsort(arr,keys,i,j, k,i2,j2) {
if(j-i<1)
return
i2=i; j2=j;
# pivot, later algorithm depends on i here,
# so be careful if going to change it
k=arr[keys[i]];
while(i2<j2) {
# push i2 to the right until there is k greater element
while(i2<=j && arr[keys[i2]]<=k) i2++;
# push j2 to the left until there is k less/equal element
while(j2>=i && arr[keys[j2]]>k) j2--;
if(i2<j2)
swapa(keys, i2, j2);
}
# if i2>j then there were no elements greater than k
# this is special case where we assume k as greatest element
# and place it to the end of the list
if(i2>j) {
swapa(keys, i, j);
i2--; j2--;
}
# recurse for subarrays
_qsort(arr, keys, i, j2);
_qsort(arr, keys, i2, j);
}
function qsort(arr,keys, n,i,k) {
for(k in arr) {
keys[++i] = k
}
n=i;
_qsort(arr, keys, 1, n);
return n;
}
BEGIN { FS="" }
{
for (i=1; i <= NF; i++) {
if ($i != " ")
letter[tolower($i)]++
}
}
#END {
# j = 1
# for (i in letter) {
# ind[j] = i
# j++
# }
# n = asort(ind)
# for (i = 1; i <= n; i++)
# printf "%s: %s\n", ind[i], letter[ind[i]]
#}
END {
j = 1
for (i in letter) {
ind[j] = i
j++}
n=qsort(letter,ind);
for(i=n; i>0; --i) {
print ind[i],letter[ind[i]];
}
}
END {
#to ="etaniosrlhdgcufm-pbyw.,v1:6kx932()-/8750qzj;][=4>+<@*'#"
to="#'*@<+>4=[];jzq0578/-)(239xk6:1v,.wybp-mfcugdhlrsoinate"
j = 1
for (i in letter) {
ind[j] = i
j++}
n=qsort(letter,ind);
for(i=1; i<=NF; i++) {
letter2[ind[i]] = substr(to, i, 1)
#print ind[i],letter[ind[i]];
}
{
for (i = 1; i<=NF; i++) {
char = substr($0, i, 1)
if (match(char, "[a-zA-Z]") != 0) {
printf("%c", letter2[char])
} else {
printf("%c", char)
}
}
printf("\n")
}}
But it doesnt work so how i need, it replace the letters wrong. Can anybody help?
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
Dear Experts,
I am using one script name :volume.sh and its written in bash shell script.
I just want to encrypt the script so that any one else cannot see it.
please tell me the commands how to encrypt the script as well as to decrypt it.
Regards,
SHARY (9 Replies)
Discussion started by: shary
9 Replies
2. Shell Programming and Scripting
Hello,
I have a text file containin 4 lines which are repeated along the file, ie
the file looks like this:
16:20:12.060769 blablabla 40
16:20:12.093199 blablabla 640
16:20:12.209003 blablabla 640
16:20:12.273179 blablabla 216
16:20:27.217444 blablabla 40
16:20:27.235410 blablabla 640... (2 Replies)
Discussion started by: Celine19
2 Replies
3. Shell Programming and Scripting
Hello
does anyone know of an awk that will extract log file entries between a specific date and time range, eg:
awk '/15\/Dec\/2010:16:10:00/, /15\/Dec\/2010:16:15:00/' access_log
but one that works?
Or a free command line log file analysis tool/script?
I'd like to be able to view... (2 Replies)
Discussion started by: competitions
2 Replies
4. Shell Programming and Scripting
Dear all,
i need your help on this. There is a text file, i need to count word frequency for each word with frequency >40 in each line of file and output it into another file with columns like this:
word1,word2,word3, ...wordn
0,0,1
1,2,0
3,2,0 etc -- each raw represents... (13 Replies)
Discussion started by: irrevocabile
13 Replies
5. UNIX for Dummies Questions & Answers
Hey Guys
I recently posted yesterday about trying to count the amount of separate words that exists in a text file e.g. walle.txt.
i want the output to give to give me a list of words with a number next indicating how many times its came up in the file e.g:
cat 20
the 11
if 40
I'm... (0 Replies)
Discussion started by: John0101
0 Replies
6. UNIX for Dummies Questions & Answers
Hey Guys,
Does anyone know how to count the separate amount of words in a text file?
e.g
the 5
and 20
Furthermore does anyone know how to convert whole numbers in decimals?
Thanks (24 Replies)
Discussion started by: John0101
24 Replies
7. Shell Programming and Scripting
I'd like to determine the frequency that each number occurs within a text file. I know how to do this for a single number, but not for a set or list of numbers. Here's what I have grep -o 01 file.txt | wc -l
Also, it's important that the numbers are two digits instead of 1, meaning that... (8 Replies)
Discussion started by: it5ju5talx
8 Replies
8. UNIX for Dummies Questions & Answers
Hi, I wanted to calculate cumulative frequency distribution of my data that involves several arithmetic calls. I did things in excel but its taking me forever. this is what I want to do:
var1.txt contains n observations which I have to compute for frequency which is given by 1/n and subsequently... (7 Replies)
Discussion started by: ida1215
7 Replies
9. UNIX for Dummies Questions & Answers
Hello everybody, i have a big issue, i have to decode a big text in base64 a lot of times but there are 2 problems: i am a noob with unix system and shell, and i have problems with openssl and i can't decode anything. can anyone decode for me that base64? need a powerful computer, i can give some... (16 Replies)
Discussion started by: supermarco2020
16 Replies
10. Shell Programming and Scripting
Hi All,
very good morning all.
I am trying to connect to informatica repository by using shell script.
I have written pmrep connect command in the script file. But i need to provide repository, domain ,username and password to connect. Username and password are hard coded in the script... (8 Replies)
Discussion started by: SekhaReddy
8 Replies
LEARN ABOUT PHP
locale_lookup
LOCALE_LOOKUP(3) 1 LOCALE_LOOKUP(3)
Locale::lookup - Searches the language tag list for the best match to the language
Object oriented style
SYNOPSIS
publicstatic string Locale::lookup (array $langtag, string $locale, [bool $canonicalize = false], [string $default])
DESCRIPTION
Procedural style
string locale_lookup (array $langtag, string $locale, [bool $canonicalize = false], [string $default])
Searches the items in $langtag for the best match to the language range specified in $locale according to RFC 4647's lookup algorithm.
PARAMETERS
o $langtag
- An array containing a list of language tags to compare to $locale. Maximum 100 items allowed.
o $locale
- The locale to use as the language range when matching.
o $canonicalize
- If true, the arguments will be converted to canonical form before matching.
o $default
- The locale to use if no match is found.
RETURN VALUES
The closest matching language tag or default value.
EXAMPLES
Example #1
locale_lookup(3) example
<?php
$arr = array(
'de-DEVA',
'de-DE-1996',
'de',
'de-De'
);
echo locale_lookup($arr, 'de-DE-1996-x-prv1-prv2', true, 'en_US');
?>
Example #2
OO example
<?php
$arr = array(
'de-DEVA',
'de-DE-1996',
'de',
'de-De'
);
echo Locale::lookup($arr, 'de-DE-1996-x-prv1-prv2', true, 'en_US');
?>
The above example will output:
de_de_1996
SEE ALSO
locale_filter_matches(3).
PHP Documentation Group LOCALE_LOOKUP(3)