帶有選項 -n 和 '$=' 的 sed 命令

帶有選項 -n 和 '$=' 的 sed 命令

我想使用sed命令列印文件中的行數。我有以下一行,請任何人詳細解釋。

sed -n '$=' myfile.txt

答案1

如果您得到一些有效的命令,但您不了解這些選項,man command請取得有關所用選項的更多資訊。man sed將向您顯示(如果您滾動/搜尋輸出):

   -n, --quiet, --silent

          suppress automatic printing of pattern space

   =      Print the current line number.

$並且(可以透過在其前面加上反斜線來進行搜尋\):

   $      Match the last line.

因此,它會為您提供最後一行的行號,而不會另外列印找到的匹配行(最後一行),這將是預設值。

答案2

=列印目前行號。$是文件中的最後一行。-n抑制通常的輸出。

相關內容