shell编程系列20--文本处理三剑客之awk常用选项
生活随笔
收集整理的這篇文章主要介紹了
shell编程系列20--文本处理三剑客之awk常用选项
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
shell編程系列20--文本處理三劍客之awk常用選項awk選項總結選項 解釋
-v 參數傳遞
-f 指定腳本文件
-F 指定分隔符
-V 查看awk的版本號[root@localhost shell]# awk -v num2="$num1" -v var1="$var" 'BEGIN{print num2,var1}'
20 hello world# -f 選項 文件中讀取表達式
[root@localhost shell]# cat 1.awk
BEGIN{str="I hava a tream"location=index(str,"ea")print location
}
[root@localhost shell]# awk -f 1.awk
12[root@localhost shell]# awk -f 2.awk
Transaction $ Start,Event ID:9002
[root@localhost shell]# cat 2.awk
BEGIN{str="Transaction 243 Start,Event ID:9002"count=sub(/[0-9]+/,"$",str)print str
}# -F 指定分隔符
[root@localhost shell]# awk -F ":" '{print $7}' passwd
/bin/bash
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/sync
/sbin/shutdown
/sbin/halt
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/sbin/nologin
/bin/bash
/sbin/nologin
/bin/bash
/sbin/nologin# 顯示版本號
[root@localhost shell]# awk -V
GNU Awk 4.0.2
Copyright (C) 1989, 1991-2012 Free Software Foundation.This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with this program. If not, see http://www.gnu.org/licenses/.
?
轉載于:https://www.cnblogs.com/reblue520/p/11016891.html
總結
以上是生活随笔為你收集整理的shell编程系列20--文本处理三剑客之awk常用选项的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Taro+react开发(29)引入固定
- 下一篇: 前端学习(3151):react-hel