2013-07-23 25 views
-2

我想從文本文件中讀取特定值,然後使用批處理腳本在其前面打印值。從文本文件讀取一個特定的字符串,然後打印它的值

腳本應該只讀所有的「總空間」下聚合列中遇到的文本文件,然後分配上校下添加和報表中的值

不能呆子,因爲它不允許安裝任何第三方我試圖運行我的腳本的mgmt服務器上的軟件。

TEXT是這樣的......

 
Total space WAFL reserve Snap reserve Usable space  BSR NVLOG   A-SIS   Smtape 
    13245GB   1324GB   596GB   11325GB    0GB    6GB    0GB 

Space allocated to volumes in the aggregate 

Volume       Allocated   Used  Guarantee 
vol0        301GB    6GB   volume 
groups        18GB   18GB   none 
userdata       665GB   662GB   none 
restricted       9GB    4GB   none 
local        16GB   10GB   none 

Aggregate      Allocated   Used   Avail 
Total space      1011GB   701GB   10306GB 
Snap reserve      596GB    7GB   588GB 
WAFL reserve      1324GB   94GB   1230GB 


Total space WAFL reserve Snap reserve Usable space  BSR NVLOG   A-SIS   Smtape 
    4138GB   413GB    0GB   3724GB    0GB   20GB    0GB 

Space allocated to volumes in the aggregate 

Volume       Allocated   Used  Guarantee 
uservol01       706GB   701GB   none 
deptvol02       367GB   364GB   none 
deptvol01       837GB   834GB   none 

Aggregate      Allocated   Used   Avail 
Total space      1911GB   1900GB   1792GB 
Snap reserve       0GB    0GB    0GB 
WAFL reserve      413GB   41GB   372GB 

Aggregate 'aggr0' 

Total space WAFL reserve Snap reserve Usable space  BSR NVLOG   A-SIS   Smtape 
     827GB   82GB    0GB   744GB    0GB   0GB    0GB 

Space allocated to volumes in the aggregate 

Volume       Allocated   Used  Guarantee 
vol0        710GB   10GB   volume 

Aggregate      Allocated   Used   Avail 
Total space       710GB   10GB   32GB 
Snap reserve       0GB    1GB    0GB 
WAFL reserve       82GB    4GB   78GB 

回答

1
@ECHO OFF 
SETLOCAL 
SET tot=0 
SET "agg=" 
FOR /f "tokens=1-3" %%a IN (yourreport.txt) DO (
IF %%a%%b==Totalspace CALL :process %%c 
IF %%a%%b==AggregateAllocated SET agg=Y 
) 
ECHO total: %tot%GB 
GOTO :EOF 

:process 
SET val=%1 
SET val=%val:~0,-2% 
SET /a tot+=val 
SET "agg=" 
GOTO :eof 

你的要求是泥濘。沒有明顯的「Aggregate」列。如果你說這應該增加產生abcd的xxx,yyy和zzz,那麼它會更清晰。事實上,這個解決方案是一個猜測。

+0

+1回答這個問題的原油。 – Endoro

+0

它的作品!輸出正是我一直在尋找的。 –

2

代碼GNU

$1=="Aggregate" {flag=1} 
$1=="Total" && flag==1 {sum=$3} 
$1=="Snap" && flag==1 {sum+=$3} 
$1=="WAFL" && flag=1 {sum+=$3; flag=0; i++; print "Volume"i, sum"GB"} 

 
>awk -f script file 
Volume1 2931GB 
Volume2 2324GB 
Volume3 792GB 

awk for Windows

相關問題