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?

More than 3 years have passed since last update.

パターンにマッチした行以降を出力

Last updated at Posted at 2021-07-09

こんにちは
パターン(pattern )にマッチ(初出)した行以降を出力しました(awk利用)1 2

$ awk "/^12/,0" sample.txt
12
12
1
$ cat sample.txt
1
12
12
1
$

他にもいくつか方法があるようです(awksedperl利用):

$ awk "/pattern/,0" sample.txt
$ sed -n '/pattern/,$p' sample.txt
$ perl -ne "print if /pattern/ .. eof;" sample.txt

grep を使う方法は:

$ grep -A999999 -e "pattern" sample.txt
$ grep -Pzo "pattern(.*\n)*" sample.txt
  1. 参考: "grep lines after match until the end" (serverfault)

  2. 参考:「今日のsed: 任意の文字列以降の行をすべて出力したい

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?