Awk Command In Shell Script Print Field

Study: a)/etc/dhcpd.conf file it contains all the Nodes Ethernet Mac Address.
b)awk Syntax - awk ' { print Argument }'
Example #ls -l | awk ' { print $2 }'
c)ether-wake Command Boot the Linux Server Remotely Using Mac Address.

1)# cat /etc/dhcpd.conf | grep ethernet
hardware ethernet 00:a0:d1:e9:b9:1a;
a)grep ethernet : grep Command It will filter the Particular Line which contain the string 'ethernet'.

2)# cat /etc/dhcpd.conf | grep ethernet | awk '{print $3}'
00:a0:d1:e9:b9:1a
b)awk '{print $3}' : It will the Print Third field.

3)#cat /etc/dhcpd.conf | grep ethernet | awk '{ print "ether-wake " $3 }'
ether-wake $3: ether-wake 00:a0:d1:e9:b9:1a.
Boot the Node which contain Mac Address 00:a0:d1:e9:b9:1a.

4)cat /etc/dhcpd.conf | grep ethernet | awk '{ print "ether-wake " $3 }' | sh
Whenever try the above Command Without | sh it will just print it will not execute the command.
like ether-wake 00:a0:d1:e9:b9:1a;
When we try with | sh then only it will execute that command.
sh It will execute the Command.

NOTE:After the system Bootup to check whether the system is UP or DOWN status
#nmap -v -sP 10.1.1.1-50 | grep appears [ Check Range from 10.1.1.1 to 10.1.1.50 ]

Actual Command - mv $9 $9.new
A)Note:Whenever we run the command Inside awk we have to put Inside " ".
Like:ls -l | awk '{ print "mv "$9" "$9".new" } '
B)Note: also for Every separate Variable
ls -l | awk '{ print "mv "$9" "$9".new" }

Some Examples with Awk Command
1)Using Mac Address Boot the all the Linux system
#cat /etc/dhcpd.conf | grep ethernet | awk '{ print "ether-wake "$3""}' | sh

 
2)Get the what are the Process (or) Command used for particular Directory or Partition
# fuser -m /opt/ | awk '{ print "ps -ax | grep "$2"" }' | sh


3)Print the List of Folder In Specified Format
# ls -l | awk '{ print "echo -n ---"$9">>scritp-output" }' | sh

`  tilde  Symbol
# awk ' { print $0 }'
$0 Whole Line    $1 First Pattern
With Sorting List Only Unique Word
#cat a | sort | uniq
Without Sorting List only the Unique Word
# awk '!x[$0]++'
List out Duplicate word (or) what are words are repeat more than one times
# awk 'x[$0]++' a

AWK Command Examples
1)#ls | awk '{ print "mv "$1" /home/hcl/code/hpl-2.0_FERMI_v15/bin/CUDA/HPL_OUTPUT/" }' | sh
2)grep -r "End of Tests" * | tee output.log
3)cat output.log | awk '{ print "mv "$0" /home/hcl/code/hpl-2.0_FERMI_v15/bin/CUDA/HPL_END_OUTPUT/"}' | sh #script -qa /dev/null | tee log.file.

Related post