Awk Processing With Files Manipulation Mathematical Operation Awk bash script Linux RHEL5

Now we do some file processing with the file rhel5. In there rhel5 file contains following words these are Linux ,ubuntu, rhel5,fedora, and UNIX using awk command we add the one word to the before of the statement and another one single word after the word.
[bash@localhost ~]# vim rhel5
[bash@localhost ~]# awk ' { print "OPEN SOURCE " $1 " Free ware"}' rhel5
OPEN SOURCE Linux Free ware
OPEN SOURCE ubuntu Free ware
OPEN SOURCE rhel5 Free ware
OPEN SOURCE fedora Free ware
OPEN SOURCE UNIX Free ware
Awk we can also perform the mathematical arithmetical operation. In these awk example the file has some mathematical no example first Linux it contains 3 3 3 it will find there average
[bash@localhost ~]# awk '{print "avg " $1 " is", ($2+$3+$4)/3}' rhel5
avg linux is 3
avg ubuntu is 4.33333
avg kubuntu is 3.66667
avg fedora is 6
avg is 0

Filter the fist and fifths field in the list out command
[bash@localhost ~]# ll | awk '{ print $1" " $5 }'
total
-rw------- 1151
drwxr-xr-x 4096
-rw-r--r-- 29588
-rw-r--r-- 3502
-rw-r--r—57
Ordinary list out
[bash@localhost ~]# ll
total 68
-rw------- 1 bash bash 1151 Oct 13 07:55 anaconda-ks.cfg
drwxr-xr-x 3 bash bash 4096 Oct 20 17:06 Desktop
-rw-r--r-- 1 bash bash 29588 Oct 13 07:54 install.log
-rw-r--r-- 1 bash bash 3502 Oct 13 07:52 install.log.syslog
-rw-r--r-- 1 bash bash 57 Oct 20 17:05 rhel5

Post a Comment

0 Comments