■ はじめに
シェルでテキスト加工するコマンドは、以下の通り。 1)awkコマンド 2)sedコマンド 3)bashによる文字列置換 などなど、、、 で、今回は、「1)awkコマンド」を扱う その他のコマンドは、以下の関連記事を参照のこと
sedコマンド
https://dk521123.hatenablog.com/entry/2019/11/23/101625
bashによる文字列置換
https://dk521123.hatenablog.com/entry/2020/03/24/223323
目次
【1】awkコマンド 1)構文 2)サンプル 【2】使用例 1)大文字 => 小文字にする 2)プロセス番号を取得する
【1】awkコマンド
* awk (オーク) * 区切り文字のテキストを処理するコマンド
1)構文
awk -F'[区切り文字]' 'パターン {アクション}' 対象ファイル名
2)サンプル
echo "1,2,4,8" | awk -F',' '{print $3}' => 4
参考文献
https://hfuji.hatenablog.jp/entry/2017/08/17/194239
【2】使用例
1)大文字 => 小文字にする
echo 'Hello World!!' | awk '{print tolower($0)}'
参考文献
https://genzouw.com/entry/2019/02/08/080904
2)プロセス番号を取得する
# まずは、プロセス一覧が取れるか試してみる $ ps aux | grep "hello.py" | grep -v grep root 179 0.0 0.4 30092 16792 ? Ss 17:00 0:00 ... ・・・ # 2列目の「179」を取得したいので # ps aux | grep "キーワード" | grep -v grep | awk '{print $2}' $ ps aux | grep "hello.py" | grep -v grep | awk '{print $2}' 179 ・・・ # 応用編は、以下の関連記事を参照のこと
grep / egrep / fgrepコマンド
https://dk521123.hatenablog.com/entry/2017/08/06/213100
関連記事
シェル について ~入門編~
https://dk521123.hatenablog.com/entry/2014/10/23/005406
sedコマンド
https://dk521123.hatenablog.com/entry/2019/11/23/101625
grep / egrep / fgrepコマンド
https://dk521123.hatenablog.com/entry/2017/08/06/213100
JDBC を シェルスクリプトでパースする ~ bash置換 ~
https://dk521123.hatenablog.com/entry/2020/03/24/223323
シェル ~ 文字列抽出あれこれ ~
https://dk521123.hatenablog.com/entry/2021/08/03/160901