awk命令详解
Posted xuqidong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了awk命令详解相关的知识,希望对你有一定的参考价值。
free -h|awk ‘NR==2‘ 396 free -h|awk ‘NR==3‘ 397 free -h|awk ‘NR==2{print $NF}‘ 398 free -h|awk ‘NR==2{print $NF,$2}‘ 399 free -h|awk ‘NR==2{print $NF/$2}‘ 400 free -h|awk ‘NR==2{print $NF/$2*100}‘ 401 free -h|awk ‘NR==2{print int($NF/$2*100)}‘ awk ‘$3~/^41/{print $1,$2,$3}‘ awk_test.txt 414 awk ‘$3~/1$|5$/{print $1$2}‘ awk_test.txt 415 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt 416 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt -n 417 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt|column -n 418 awk ‘$3~/1$|5$/{print $1,$2}‘ awk_test.txt|column -t 419 awk ‘$3~/[15]$/{print $1,$2}‘ awk_test.txt|column -t 420 awk ‘$3~/(1|5)$/{print $1,$2}‘ awk_test.txt|column -t 421 ! 422 cat awk_test.txt 423 awk ‘$2~/Xiaoyu/{gsub(/:/,"$",$NF),print $NF}‘ awk_test.txt 424 awk ‘$2~/Xiaoyu/{gsub(/:/,"$",$NF);print $NF}‘ awk_test.txt 425 history 426 vim awk_test.txt 427 cat awk_test.txt 428 awk ‘/^#|^$/‘ awk_test.txt 429 awk ‘/!^#|^$/‘ awk_test.txt 430 awk ‘!/^#|^$/‘ awk_test.txt 431 awk ‘$0~/^#|^$/‘ awk_test.txt 432 awk ‘$0!~/^#|^$/‘ awk_test.txt 433 iP a 434 ip a 435 ip a s 436 ip a s eth0 437 ip -n 438 ip --h 439 ip a s --h 440 man ip 441 ip a sh 442 ip a sh eth0 443 ip a sh eth0|awk -F "[/]{print $2}" 444 ip a sh eth0 445 ip a sh eth0|awk -F "/" ‘NR==2‘ 446 ip a sh eth0|awk -F "/" ‘NR==3‘ 447 ip a sh eth0|awk -F "/" ‘NR==3{print $2}‘ 448 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $2}‘ 449 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $3}‘ 450 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $1}‘ 451 ip a sh eth0|awk -F "[ /]+" ‘NR==3{print $3}‘ 452 hostname -i 453 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}‘ 454 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt 455 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt |coulmn -t 456 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt |column -t 457 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}‘ awk_test.txt |column -t 458 awk ‘BEGIN{print "姓","名","QQ号","捐款记录"}{print $0}‘ awk_test.txt |column -t 459 awk ‘BEGIN{print 1+1}‘ 460 awk ‘BEGIN{print 1-9}‘ 461 awk ‘BEGIN{print 1*9}‘ 462 awk ‘BEGIN{print 1/9}‘ 463 echo $((1+9)) 464 echo $((1/9)) 465 cat awk_test.txt 466 awk ‘BEGIN{FS=":"}{print $2}END{print "操作结束"}‘ awk_test.txt 467 awk -vqhy=123 ‘{print qhy}‘ awk_test.txt 468 grep ‘^$‘ /etc/services 469 grep ‘^$‘ /etc/services -c 470 awk ‘/^$/{i=i+1;print i}‘ /etc/services 471 awk ‘/^$/{i++;print i}‘ /etc/services 472 awk ‘/^$/{i++}END{print i}‘ /etc/services 473 cat /etc/passwd 474 awk ‘$NF~/bash/‘ /etc/passwd 475 awk ‘$NF~/bash/{i=i+1}END{print i}‘ /etc/passwd 476 awk ‘$NF!~/bash/{i=i+1}END{print i}‘ /etc/passwd 477 awk ‘$NF!~/bash/‘ /etc/passwd 478 awk ‘$NF!~/bash/{i=i+1}END{print i}‘ /etc/passwd 479 seq 10 480 awk ‘{sum=sum+$n,print sum}‘ 481 awk ‘{sum=sum+$n;print sum}‘ 482 seq 10|awk ‘{sum=sum+$n;print sum}‘ 483 cat awk_test.txt 484 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt 485 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum=sum+$n;print $n}‘ 486 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘$1~{sum=sum+$n;print $n}‘ 487 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘$1~{sum=sum+$n;print}‘ 488 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum=sum+$n}‘ 489 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum=sum+$n;print $0}‘ 490 seq 10|awk ‘{sum=sum+$1;print sum}‘ 491 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘ 492 vim awk_test.txt 493 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘ 496 awk -F ":" ‘BEGIN{print "第一次捐款总额","第二次捐款总额"}{print $2,$NF}‘ awk_test.txt |awk ‘{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘ 497 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘BEGIN{print "第一次捐款总额","第二次捐款总额"}{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘ 498 awk -F ":" ‘{print $2,$NF}‘ awk_test.txt |awk ‘BEGIN{print "第一次捐款总额","第二次捐款总额"}{sum1=sum1+$1;sum2=sum2+$2;print sum1,sum2}‘|column -t
以上是关于awk命令详解的主要内容,如果未能解决你的问题,请参考以下文章