0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

awkで最後フィールドを取得する

Posted at

自分がいるディレクトリのパスを除いたのがほしいなあ、と思った次第で

組み込み変数の NF を使用します。

pwd | awk -F'/' '{print $NF}'

man を確認すると単にレコード(行)の最後のフィールド(列)の数値を表してるだけなので、
以下のような使い方をすると最後から一つ前、とかも可能。

pwd | awk -F'/' '{print $(NF - 1)}'
0
0
0

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?