0

嗨,我想创建一个脚本,将附加到现有文件:这是文件的外观:

{| 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 字段下为“日期”添加一个条目,例如:

|-
! 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
}

谢谢

4

1 回答 1

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
于 2013-09-04T13:15:33.557 回答