How correctly parsed vars in Awk
Hi, I wrote a script for "Data Protector" that output a list and I want to filter its items and arrange them in columns. The script comes:
omnidb -session -type backup -since $Yesterday -until `date '+%Y/%m/%d'` -detail|grep -E "Specification|SessionID|Started|Finished|Host|Status"|sed 's/://g'|sed 's/Backup Specification/Specification/g'|awk '{print $1,$2$3$4$5}' This is the list that I have from that script SessionID 2009/08/17-42 Specification ar-gecs21_FS_Daily Started Mon Aug 17 210002 Finished Mon Aug 17 210226 Status Completed Host nols17 SessionID 2009/08/17-44 Specification Disco_Servers_10pm_FS_Daily-2 Started Mon Aug 17 220001 Finished Tue Aug 18 045352 Status Completed Host nols17 SessionID 2009/08/17-47 Specification Telco-DCN-FS-Daily-22_hs Started Mon Aug 17 220016 Finished Mon Aug 17 225652 Status Completed Host nols17 SessionID 2009/08/17-48 Specification MSSQL TPARADM04_SQL_Daily Started Mon Aug 17 220036 Finished Mon Aug 17 235236 Status Completed Host nols17 SessionID 2009/08/17-51 Specification Disco_D095NWSHTEC05_FS_Daily-2 Started Mon Aug 17 221502 Finished - Status In Progress/Errors Host nols17 This is how I'd arranged the output in columns: ...|awk \ { if ( $1 ~ /SessionID/ ) SI=`print $2` printf ("%s\n",SI) ; }' And this is what I got when execute the script: syntax error The source line is 4. The error context is >>> SI=` <<< awk: The statement cannot be correctly parsed. The source line is 4.:scratch: I think I'm wrong about how store "print $2" into a variable If anybody have any comment about it I'll be very grateful Thanks to all :p |
To store a string in a variable, just assign the value to that variable:
Code:
SI = $2 Code:
printf "%s\n", $2 Code:
... | awk '$1 ~ "SessionID" {print $2}' |
Quote:
But now I have this output: 2009/08/17-1 2009/08/17-1 2009/08/17-1 2009/08/17-1 2009/08/17-1 2009/08/17-1 2009/08/17-4 2009/08/17-4 2009/08/17-4 2009/08/17-4 2009/08/17-4 2009/08/17-4 2009/08/17-6 2009/08/17-6 2009/08/17-6 2009/08/17-6 2009/08/17-6 2009/08/17-6 2009/08/17-8 2009/08/17-8 2009/08/17-8 2009/08/17-8 2009/08/17-8 2009/08/17-8 When I just need 2009/08/17-1 2009/08/17-4 2009/08/17-6 2009/08/17-8 I cannot use uniq at the end because the idea is: { if ( $1 ~ /SessionID/ ) SI=`print $2` printf ("%s\n",SI) ; }' { if ( $1 ~ /Specification/ ) SP=`print $2` printf ("%s\n",SP) ; }' { if ( $1 ~ /Status/ ) ST=`print $2` printf ("%s\t%s\t%s\n",SI,SP,ST) ; }' ..... :( ¿? |
sorry
I meant when I replied: { if ( $1 ~ /SessionID/ ) SI= $2 if ( $1 ~ /Specification/ ) SP= $2 if ( $1 ~ /Status/ ) ST= $2 printf ("%s\t%s\t%s\n",SI,SP,ST) ; }' ..... |
I don't understand what you really want to obtain. Please, write a sample of the desired output (full version, not only the first part of the lines).
|
In any case take in mind that the repetition is because the printf statement is executed for each input line. If you want to execute it inside the last if block you have to use brackets, since you use a multi-line block of code:
Code:
{ |
Thanks a lot Colucix!!!
You realy have it clear. Here is how the script left: ... { if ( $1 ~ /SessionID/ ) SI= $2 if ( $1 ~ /Started/ ) ST= $2 if ( $1 ~ /Finished/ ) FN= $2 if ( $1 ~ /Host/ ) HT= $2 if ( $1 ~ /Status/ ) TT= $2 if ( $1 ~ /Specification/ ) { SP= $2 printf ("%s\t%s\t%s\t%s\t%s\t%s\n",SI,ST,FN,HT,TT,SP) } }' And the output: [nols17 /home/root/Azk]# ./version2 Session_ID Started Finished Host Status Specification ____________________________________________________________________________________________________ ___________________ 2009/08/17-1 MonAug17000001 MonAug17154414 nols17 Completed Telco-DCN_FS_Daily 2009/08/17-4 MonAug17000001 MonAug17154423 nols17 Completed IT_Archivelog_FS_Daily 2009/08/17-6 MonAug17001501 MonAug17001858 nols17 Completed MSSQLPaxMobiles_SQL-Dbserver1_Daily 2009/08/17-8 MonAug17013001 MonAug17020827 nols17 Completed Disco_Servers_230am_FS_Daily 2009/08/17-10 MonAug17023001 MonAug17023314 nols17 Completed GE_OL_FS_Daily 2009/08/17-12 MonAug17030001 MonAug17075232 nols17 Completed Disco_D208srtec07_FS_Daily 2009/08/17-14 MonAug17040001 MonAug17090719 nols17 Completed/Failures Disco_Servers_4am_FS_Daily 2009/08/17-17 MonAug17040007 MonAug17053526 nols17 Completed IT_UnixFS_Daily2 2009/08/17-20 MonAug17061501 MonAug17062904 nols17 Completed IT_UnixFS_Daily3 2009/08/17-22 MonAug17061515 MonAug17062500 nols17 Completed Disco_Servers_7am_FS_Daily 2009/08/17-24 MonAug17070001 MonAug17070655 nols17 Completed Servers_standard_FS_Daily 2009/08/17-26 MonAug17070016 MonAug17103530 nols17 Completed/Errors Disco_Servers_10pm_FS_Weekly-2 2009/08/17-28 MonAug17073115 MonAug17122505 ar-nolp21.ol.mr Failed Disco_D095NWSHTEC05_FS_Daily 2009/08/17-30 MonAug17080001 MonAug17100446 nols17 Completed ar-gecs22_FS_Daily 2009/08/17-32 MonAug17131502 MonAug17144902 nols17 Completed ar-gecs43-ar-gecs42_FS_Daily 2009/08/17-34 MonAug17131504 MonAug17132204 nols17 Completed Ar-nols_Daily 2009/08/17-40 MonAug17131507 MonAug17133849 nols17 Completed Omniback_Database_Daily 2009/08/17-42 MonAug17164502 MonAug17213649 nols17 Completed ar-gecs21_FS_Daily 2009/08/17-44 MonAug17210002 MonAug17210226 nols17 Completed Disco_Servers_10pm_FS_Daily-2 2009/08/17-47 MonAug17220001 TueAug18045352 nols17 Completed Telco-DCN-FS-Daily-22_hs 2009/08/17-48 MonAug17220016 MonAug17225652 nols17 Completed MSSQLTPARADM04_SQL_Daily 2009/08/17-51 MonAug17220036 MonAug17235236 nols17 Completed Disco_D095NWSHTEC05_FS_Daily-2 Thanks a lot again!!! |
All times are GMT -5. The time now is 06:58 AM. |