Sunday, June 14, 2009

vowel count in a file ..........

A script count the number of occurance of vowels in particular file

i.e how Many times a vowel come in the file ....

grep -io [aeiouAeIOU] |sort|uniq -c

alphabetical order words...

Hiii Friends..

This time i have come with a prob..

Prob is : You have to print the all worlds in a file that are in increasing order..
i.e. abcd.. qrstz.. but it can't be like dcefgh...because c followed by d contradict the rules.

Thak you In Advance....

Saturday, June 6, 2009

a useful single liner for windows user.....

hiiii folks...

some time u have been facing prob in windows that due to some virus aur intruders attack there is an .exe file created in every folder with the same name as the folder..

it is very cumbersome to delete all those files manually...

my suggestion is if ur system is dual boot system..
1.) goto ur linux box..
2.) mount ur windows drives..
3.) become root user with su on fedora,redhat,mandriva or sudo su on ubuntu..
3.) run thd following command...
find / -name "*.exe" -print | awk -F"/" '{split($NF,a,"."); if($(NF-1)==a[1]){ print $0}}'

it will print all those files on your system any where which has the same name as its folder name.

4.) after inspecting the output if u r satisted ..
5.) run again the following command

find / -name "*.exe" -print | awk -F"/" '{split($NF,a,"."); if($(NF-1)==a[1]){ print $0}}' | xargs rm -f

friends u will not believe !.. it will wipe out ur all such files on your system in one go..

I think it will be useful..

Enjoy Linux !!...
if you find it is useful plzzzzzz do comment on this post !!...

single liner to calculate the sum of digits of a number...

let us suppose no. is 12647424
answer should be 1+2+6+4+7+4+2+4=30

logic is inferred from above line..

first number is converted .. e.g.

287 is converted as 2 + 8 + 7
and now apply expr commad on above pattern u will get answer..

now how to convert 287 to 2 + 8 + 7

echo $num | sed -e 's/[0-9]/ + &/g' -e 's/^ +//'`

will convert 287 to 2 + 8 + 7

now simply use expr over the above string...

expr `echo $num | sed -e 's/[0-9]/ + &/g' -e 's/^ +//'`

is it not amazing... free from looping construct....(as every one does...)
enjoy !!....

cool ways to count no. occourences of each words in a file....

Here i m giving ways to count frequency of each words in file..i.e. how many times a word is found...

1.)

awk '{ for(i=1;i<=NF;i++){a[$i]++;}} END{for(i in a) print i" "a[i]}' filename

filename must be raplaced by ur desired filename.

2.)

cat filename | tr '[ ]+' '\n' | sort | uniq -c

logic is convert all spaces n tabs to newline.
this will convert all words in a file to single line.
now sort the output..
find unique word with their count with -c option of uniq.

i m searching for other method too..
if u found then let the others know..

enjoy scripting.....