4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[awk] exit文でawkの実行処理を終了

Last updated at Posted at 2015-06-17

awkでは、exit文を使うと、処理の途中でもawkを終了させることができます。

$ cat test.txt
1
2
3
4
5
$ awk '{
    print $1;
    if ($1 == 3) exit;
}' test.txt
1
2
3

4, 5は出力されていません。

注意

なお、exit文を実行しても、ENDブロックは実行されるので注意してください。

$ awk '{
    print $1;
    if ($1 == 3) exit;
}
END {
    print "実行されます!";
}' test.txt
1
2
3
実行されます!
4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?