您好我想创建一个附加到现有文件的脚本:这是文件的外观:
{| border="1" cellspacing="5" cellpadding="2" style="text-align: center;"
|-
! DataStore-1:
! 11/14/12
! 11/16/12
! 11/30/12
|-
| Total ios
| [[File:datastore-1-Tios-11-14-2012.png| 100px]]
| [[File:datastore-1-Tios-11-16-2012.png| 100px]]
| [[File:datastore-1-Tios-11-30-2012.png| 100px]]
|-
| Read %
| [[File:datastore-1-readp-11-14-2012.png| 100px]]
| [[File:datastore-1-readp-11-16-2012.png| 100px]]
| [[File:datastore-1-readp-11-30-2012.png| 100px]]
|-
| Cache Hit %
| [[File:datastore-1-cachep-11-14-2012.png| 100px]]
| [[File:datastore-1-cachep-11-16-2012.png| 100px]]
| [[File:datastore-1-cachep-11-30-2012.png| 100px]]
|-
| Current kB/sec
| [[File:datastore-1-ckbsec-11-14-2012.png| 100px]]
| [[File:datastore-1-ckbsec-11-16-2012.png| 100px]]
| [[File:datastore-1-ckbsec-11-30-2012.png| 100px]]
|-
| Maximum kB/sec
| [[File:datastore-1-mkbsec-11-14-2012.png| 100px]]
| [[File:datastore-1-mkbsec-11-16-2012.png| 100px]]
| [[File:datastore-1-mkbsec-11-30-2012.png| 100px]]
|-
| Current IO/sec
| [[File:datastore-1-ciosec-11-14-2012.png| 100px]]
| [[File:datastore-1-ciosec-11-16-2012.png| 100px]]
| [[File:datastore-1-ciosec-11-30-2012.png| 100px]]
|-
| Max IO/sec
| [[File:datastore-1-miosec-11-14-2012.png| 100px]]
| [[File:datastore-1-miosec-11-16-2012.png| 100px]]
| [[File:datastore-1-miosec-11-30-2012.png| 100px]]
|-
|}
基本上我希望能够在DataStore-1字段下添加“date”条目,例如:
|-
! DataStore-1:
! 11/14/12
! 11/16/12
! 11/30/12
! 12/03/12
|-
一旦我这样做,我还想为使用相同变量日期的每个其他字段添加一个附加条目,例如:
| -
| Total ios
| [[File:datastore-1-Tios-11-14-2012.png| 100px]]
| [[File:datastore-1-Tios-11-16-2012.png| 100px]]
| [[File:datastore-1-Tios-11-30-2012.png| 100px]]
| [[File:datastore-1-Tios-12-03-2012.png| 100px]]
|-
[...]
我正在考虑为我的文件的每个部分创建一个函数,但我的逻辑足够......
writedates ()
{
SOURCEFILE=/mnt/bacchuscore-logger/netmon/wikipages/sourcefile.wk
DATASTORENUM=`head -1 $SOURCEFILE|cut -d '=' -f2`
DATESECTION=dates.sec
DATEOUTPUT=newdates.sec
i=0
while read; do
VAR[$i]=$REPLY
DSN=$(echo ${VAR[0]}|cut -d '=' -f2)
DSF=$(echo ${VAR[1]}|cut -d '=' -f2)
DE=$(echo ${VAR[2]}|cut -d '=' -f2)
echo "! $DSF-$DSN"
echo "! $DE"
echo "|-"
((i++))
done < $SOURCEFILE
}
感谢
答案 0 :(得分:0)
这些脚本行会在文件中插入其他条目,假设变量date
包含新日期(例如date=12/03/12
),文件名为datastore
:
set ${date//// }; datex=$1-$2-20$3.png
sed -f-<<EOF -i datastore
/^! DataStore-1:/,/^|-/s,^|-,! $date\n&,
/^| Total ios/,/^|-/s,^|-,| [[File:datastore-1-Tios-$datex| 100px]]\n&,
/^| Read %/,/^|-/s,^|-,| [[File:datastore-1-readp-$datex| 100px]]\n&,
/^| Cache Hit %/,/^|-/s,^|-,| [[File:datastore-1-cachep-$datex| 100px]]\n&,
/^| Current kB\/sec/,/^|-/s,^|-,| [[File:datastore-1-ckbsec-$datex| 100px]]\n&,
/^| Maximum kB\/sec/,/^|-/s,^|-,| [[File:datastore-1-mkbsec-$datex| 100px]]\n&,
/^| Current IO\/sec/,/^|-/s,^|-,| [[File:datastore-1-ciosec-$datex| 100px]]\n&,
/^| Max IO\/sec/,/^|-/s,^|-,| [[File:datastore-1-miosec-$datex| 100px]]\n&,
EOF