#!/usr/local/bin/ruby # -*- coding: utf-8 -*- while line=gets if /^#/ =~ line then # 行の先頭が # なら処理を飛ばす next elsif /^(\S+)\s+(\d+)\s+(\d+)\s+(\d+)$/ =~ line then # ↑ ↑ ↑ ↑ # 品目 仕入れ単価 販売単価 在庫数 # $1 $2 $3 $4 # \S は 空白でない任意の1文字,\s は 空白1文字,\d は 数字1文字 ap = $3.to_i n = $4.to_i printf("品目%s の販売単価は%d円で%d個あります\n", $1, ap, n) end end