月度归档:2012年05月

【转】awk實現求和、平均、最大值和最小值的計算操作

0、准备和数据文件

比如有一个数据文件,只有一列(在之前可以通过各种手段过滤出只有数字这一列),比如操作的响应时间

  1. 490898  
  2. 1189235  
  3. 20212  
  4. 1494270  
  5. 146515  
  6. 29369  
  7. 23563  
  8. 563027  
  9. 22976  
  10. 127809  
  11. 16813  
  12. 551646  
  13. 18858  
  14. 18977  

 

1、求和

cat data|awk '{sum+=$1} END {print "Sum = ", sum}' 

 

2、求平均
cat data|awk '{sum+=$1} END {print "Average = ", sum/NR}' 

 

3、求最大值
cat data|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Max=", max}'

 

4、求最小值(min的初始值设置一个超大数即可)
awk 'BEGIN {min = 1999999} {if ($1<min) min=$1 fi} END {print "Min=", min}'

 

5、求访问次数的Top 10 Resource,可以根据此进行优化

cat output/logs/cookie_logs/`date +%u`/cookie_log|grep -v '172.16'|grep -v '127.0.0.1' |awk -F' '  '{ if(index($1,"219.141.246")!=0) print $2; else print $1  } '|sort|uniq -c|sort -n |tail -n 10

转自:http://lixjluck.iteye.com/blog/961271

【转】drupal 内部变量

$base_path:Drupal 安装的基本路径。如果安装在根目录下,这是最简单的,他将默认为根目录。
$breadcrumb: Returns the HTML for displaying the navigational breadcrumbs on the page.
$closure:返回hook_footer()的输出,它常在页面的底部使用。
$css:.返回一个所有css 文件组成的数组结构,以添加到页面中去。使用$styles来返回
$css 数组的HTML 版本。
$content:返回将要展示的HTML 内容.例如,它可以包含一个节点,一组节点,管理接口的内容,等等。
$directory:主题所在的相对路径。例如themes/bluemarine或者sites/all/themes/custom/mytheme。
  通常联合使用该变量和$base_path 来构建你的站点主题的绝对路径:<?php print $base_path . $directory ?>
$feed_icons:返回该页面的RSS种子链接
$footer_message:返回页脚信息文本,在下面页面输入它:Administer ➤Site configuration ➤ Site information.
$head:返回放置在<head></head>部分的HTML。模块可以通过调用drupal_set_html_head()
  来向$head添加额外的比如RSS种子的纯文本。
$head_title:在页面标题中展示的文本,放在HTML <title></title>标签中。
$help: 帮助文本,大多数用于管理页面。模块可以通过实现hook_help()来提供该变量。
$is_front: 如果当前展示的为首页的话为真TRUE。
$language:站点展示时所使用的语言
$layout:这一变量允许你定义外观的不同类型的风格,而变量$layout的值依赖于启用的工具条(sidebars)的数量。
  可能的值包括:none, left,right, and both.
$logo: 指向logo 图像的路径,在启用主题的主题配置页面定义。通常这样使用:
  <img src="<?php print $logo ?>" />
$messages: 为表单或者其他信息返回的验证错误和正确的提示信息的HTML。它通常显示在页面的头部。
$mission: 返回站点使命文本,在Administer ➤ Site configuration ➤ Site information中输入.
  只有当$is_front 为TRUE 时才可以使用。
$node:整个节点对象,当察看一个单独节点页面时可用。
$primary_links: 一个包含了一级链接的数组。在Administer ➤ Site building ➤Menus中定义它们。
  通常$secondary_links通过函数theme('links')来定制输出的样式,
如下所示:
<?php print theme('links', $primary_links) ?>
$scripts: 返回向页面的<script>标签中所添加的HTML。这也是关于jQuery 如何被加载的
$search_box: 返回搜索表单的HTML。当管理员在启用的主题中的主题配置页面禁止展示搜索时,
  或者搜索模块禁用时,$site_slogan为空。
$secondary_links: 一个包含了二级链接的数组。在Administer ➤ Site building ➤Menus中定义它们。
  通常$secondary_links通过函数theme('links')来定制输出的样式,
如下所示:
<?php print theme('links', $secondary_links) ?>
$sidebar_left:返回左边工具条的HTML,包含了属于该区域的所有区块的HTML。
$sidebar_right:返回右边工具条的HTML,包含了属于该区域的所有区块的HTML。
$site_name: 站点的名称。在Administer ➤Site configuration ➤Site information中设置。
  当管理员在启用的主题中的主题配置页面禁止展示标语时,$site_ name为空。
$site_slogan: 站点的标语。在Administer ➤ Site configuration ➤Site information中设置。
  当管理员在启用的主题中的主题配置页面禁止展示标语时,
$site_slogan 为空。
$styles:返回连接到页面需要的CSS文件的HTML。CSS文件通过drupal_add_css() 添加到$styles中去。
$tabs: 返回用于为节点展示诸如View/Edit的标签的HTML
$title:主内容的标题,与$head_title不同。当察看一个单独节点视图页面时,$title就是节点的标题。
  当常看Drupal的管理员页面时,$title通常有菜单项来设置,菜单项对应于查看的页面。
 

转自:程序人生

【转】Drupal 主题文件Page.tpl.php中的可用变量

$base_path
Returns the base URL path of the Drupal installation. At the very least, this will always default to /.
$breadcrumb
HTML for displaying the breadcrumbs at the top of the page.
$closure
Needs to be displayed at the bottom of the page, for any dynamic javascript that needs to be called once the page has already been displayed.
$content
The HTML content generated by Drupal to be displayed.
$css
An array of all the CSS files for the current page.
$directory
The directory the theme is located in, e.g.
themes/garland or themes/garland/minelli.
$feed_icons
A string of all feed icons for the current page.
$footer_message
The footer message as defined in the admin settings, also the HTML for the footer region.
$head
HTML as generated by drupal_get_html_head().
$head_title
The text to be displayed in the page title.
$header
HTML for the header region.
$help
Dynamic help text, mostly for admin pages.
$is_front
True if the front page is currently being displayed. Used to toggle the mission.
$language
The language the site is being displayed in.
$layout
This setting allows you to style different types of layout ('none', 'left', 'right' or 'both') differently, depending on how many sidebars are enabled.
$logo
The path to the logo image, as defined in theme configuration.
$messages
HTML for status and error messages, to be displayed at the top of the page.
$mission
The text of the site mission, empty when display has been disabled in theme settings.
$node
(5.x and after only) If you are in page.tpl.php displaying a node in full page view then $node is available to your template.
$onload_attribute
(4.7 and older only) Onload tags to be added to the head tag, to allow for autoexecution of attached scripts.
$primary_links (array)
An array containing the links as they have been defined in the phptemplate specific configuration block.
$scripts
(5.x and after only) HTML to load the JavaScript files and make the JS settings available. Previously, javascript files are hardcoded into the page.tpl.php
$search_box
True(1) if the search box has been enabled.
$search_button_text
(4.7 and older only)Translated text on the search button.
$search_description
(4.7 and older only)Translated description for the search button.
$search_url
(4.7 and older only)URL the search form is submitted to.
$secondary_links (array)
An array containing the links as they have been defined in the phptemplate specific configuration block.
$sidebar_left
The HTML for the left sidebar.
$sidebar_right
The HTML for the right sidebar.
$site_name
The name of the site, empty when display has been disabled in theme settings.
$site_slogan
The slogan of the site, empty when display has been disabled in theme settings.
$styles
Required for stylesheet switching to work. This prints out the style tags required.
$tabs
HTML for displaying tabs at the top of the page.
$title
Title, different from head_title, as this is just the node title most of the time.

See also page.tpl.php for Drupal 6 and higher.
转自:Drupal官网