You are on page 1of 2

wishme

date +%H | awk '{


if($0>=0 && $0<12)
print "Good Morning!"
else if($0<16)
print "Good Afternoon!"
else
print "Good Evening!"
}'

verbosedate

fages

stat -c %Z" "%n *.*| awk -v s=$(date +%s) '{


years=int(int((s-$1)/(60*60*24))/365)
rem=int((s-$1)/(60*60*24))%365
months=int(rem/30)
rem=int((s-$1)/(60*60*24))%30
printf "%s\t%d Years %d Months %d days\n",$2,years,months,days
}'

word-freq

awk '{
for(i=1;i<=NF;i++)
words[$i]++
}
END {
for(word in words)
print word,words[s]
}' emp.dat

wordcount

awk '{
noofword+=NF
}
END { print noofword }' emp.dat

backwards

awk '{
for(i=NF;i>0;i--)
print $i
}' emp.dat

salestotals
sales
raj 2342
qwe 456
raj 4533
raj 123
qwe 986
asd 1234
program:
awk '{
sales[$1]+=$2
} END{
for(s in sales)
print s,sales[s]
}' sales

events:
events:
27 Jan UNIX Class
27 Jan .net Class
28 Jan UNIX Lab in RPH
28 Jan UNIX class in 4th hour
28 Jan .NET Class in 5th hour
program:
awk -v tday=$(date +%d) -v mon=$(date +%b) '{
if($1==tday && $2==mon)
print $0
}' events

Squeeze:
awk '{
gsub(/[ ]+/," ")
print $0
}' temp

replaceover
awk '{
gsub("hi","Hello")
}' temp

You might also like