電子書籍の厳選無料作品が豊富!

シェルスクリプト超初心者なので、どなたかにご教授をお願いできれば
と思います。

行いたい処理は以下の通りです。

#fdisk -ul /dev/sda

Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 63 208844 104391 83 Linux
/dev/sda2 208845 83875364 41833260 8e Linux LVM

とfdiskコマンドによって表示されたものに対して、
255 heads, 5221 cylinders, 83886080 sectors
の部分を読み取り、output.txtに以下のように書き出したい。
# cat output.txt
heads = "255"
cylinders = "5221"
sectors = "83886080"

以上ですが、どなたかサンプルコードを提供していただけないのでしょうか。

よろしくお願い致します。

A 回答 (2件)

fdisk -ul /dev/sda | awk '


/heads/ {
printf ("heads=\"%d\"\ncylinders=\"%d\"\nsectors=\"%d\"\n",$1,$5,$8);
}'
    • good
    • 0
    • good
    • 0

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!