LoginSignup
0
0

More than 1 year has passed since last update.

【Linux】特定の文字列を検索して行番号のみを取得する方法

Posted at

取得方法

sedコマンドを使用して以下のように実行することで行番号のみを取得できます。

sed -n '/検索する文字列/=' sample.txt

以下のような内容でsample.txtを作成します。

sample.txt
12345
あいうえお
12345
あいうえお
12345
あいうえお
12345
あいうえお
12345
あいうえお

1が含まれる行の行番号を取得するために以下のコマンドを実行します。

$ sed -n '/1/=' sample.txt
1
3
5
7
9

上記のように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