補覺鳴詩

學海無涯


  • 首頁

  • archive

  • 關於我

  • 搜尋

devops text manipulation tools

時間: 0001-01-01   |   分類: devops   linux   devops tool   | 字數: 181 字 | 閱讀: 1分鐘 | 閱讀次數:

devops 經常需要操控 text 文字 這裡整理常用的工具以及範例

參考資料來源 https://roadmap.sh/devops

awk

awk 用於執行 AWK programming language 該 language 專門用於文字的操控 比如說 sum of all values of column 3 pattern scanning and processing language Syntax

awk '/search pattern1/ {Actions}
/search pattern2/ {Actions}' file

範例文件 abc.csv

id,name,city,salary
1,Mike,NYC,20000
2,John,Chicago,40000
3,Jerry,Orlando,50000
4,Jaime,San Francisco,100000
5,Bill,Seattle,70000
6,Sam,Chicago,80000

列出文件中該行中包含的 Mike 及 Bill

owan@node1:~$ awk '/Mike/
/Bill/' abc.csv
1,Mike,NYC,20000
5,Bill,Seattle,70000

設定分隔符號 (預設為 空格)

# 使用 : 分隔
gawk -F: '{ print $1 }' /etc/passwd
使用 log 並顯示一個
echo a.lo.log.log.log.log | awk -F'\\.log\\.' '{ print $1 }'
a.lo

替換字串 gsub(ere, repl[, in])

echo "a b c 2011-11-22 a:d" | awk '$4=gsub(/-/,"",$4)'

sed grep sort uniq cat ccut echo fmt tr nl egrep fgrep wc

#devops# #linux# #devops tool#
comments powered by Disqus >
  • 文章目錄
  • 網站導覽
Owan

Owan

愛貓如癡

131 日誌
29 分類
37 標籤
GitHub
  • awk
© 2010 - 2022 補覺鳴詩
Powered by - Hugo v0.96.0 / Theme by - NexT
0%