LoginSignup
0

More than 3 years have passed since last update.

awkのフィールド操作Tips

Posted at

空白を整理する

$ echo ' 1  2 3   4  ' | awk '{$1=$1; print}'
1 2 3 4

任意のフィールドを削除する

$ seq 1 5 | xargs | awk '{$1=""; $0=$0; $1=$1; print}'
2 3 4 5

フィールドの末尾を削る

$ seq 1 5 | xargs | awk '{NF=NF-2; print}'
1 2 3

フィールドを付け足す

$ seq 1 5 | xargs | awk '{$0=$0FS 6; print}'
1 2 3 4 5 6

フィールドを挿入する

$ seq 1 5 | xargs | awk '{$3=$3FS 6; $0=$0; print}'
1 2 3 4 5 6

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0