Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php): failed to open stream: No such file or directory in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: include(): Failed opening '/home/blog66rr/public_html/wp-content/plugins/hyper-cache/cache.php' for inclusion (include_path='.:/opt/cpanel/ea-php70/root/usr/share/pear') in /home/blog66rr/public_html/wp-content/advanced-cache.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at /home/blog66rr/public_html/wp-content/advanced-cache.php:24) in /home/blog66rr/public_html/wp-includes/feed-rss2.php on line 8
awk – unethost無限空間虛擬主機 技術分享部落格 https://blog.unethost.com unethost 專注於提供優質的虛擬主機服務及相關問題解答 Wed, 16 Apr 2014 08:34:36 +0000 zh-TW hourly 1 https://wordpress.org/?v=6.0.8 awk抓成績 https://blog.unethost.com/awk-get-data/ Tue, 15 Nov 2011 06:09:45 +0000 http://blog.unethost.com/?p=36 閱讀全文 awk抓成績]]> 最近接的一個case,是東光舞蹈教室的自由盃網站維護:客戶的要求之一,是要在網站上提供17屆、18屆的比賽成績連結。跟客戶要資料時,客戶表示,在某某網站上就可以”抓”了。像這個網站

由於我太好凹了,就算了很便宜的價錢給客戶,不過是個成績網頁嘛,就是複製、貼上,修一下html,就結束了。(我是這樣想的。) 真的開始做的時候,才發現,糗大了。那個客戶叫我去抓資料的網站… 怎麼會出來的html,居然是…硬寫的。完全沒有<tr><td>。這叫我要怎麼湊啊。

後來,我想了一招:來吧, awk

cat original | awk '{if ($3!="") {print "array( " $1"," $2",\""
$3"\",\""$4"\"),"} else { if ($1!="") { print "\""$1"\"=>array("  } else
{print "\n" }  }  }'

試了一下噁心的awk指令,似乎有好一些了…
至少…打幾個字就變成可以用的code了。

"業餘組A組拉丁_決賽"=>array(
array( 名次,背號,"選手姓名一","選手姓名二"),
array( 1,138,"Patara","Melissa"),
array( 2,134,"潘彥儒","吳靜雯"),
array( 3,122,"劉漢偉","姚又齊"),
array( 4,139,"Puttipong","Sahaifa"),
array( 5,132,"鄭嘉文","石毓琳"),
array( 6,143,"賴建霖","郝偵汝"),
array( 7,144,"曾洺寘","李安洏"),
array( 8,137,"吳京橋","林婉姍"),
array( 9,145,"楊東原","陳蘭芳"),

 

]]>