Awk

command line

awk 'BEGIN{v_list="hello good well done";n=split(v_list,ch);i=1;while(i<=n){print ch[i];i++}}'

Tips

awk -F[分隔符集] '{print $1}' filename     #使用两个分隔符
awk '{sum+=$1}; END{print sum}' #求和

AWK Array Script To Find File Maximum, Minimum and Total File Sizes

#!/bin/bash 
# Written by Vivek Gite <www.cyberciti.biz> 
# AWK to list total file size, minimum, maximum and other size using Arrays 
# -------------------------------------------------------------------------- 
# Copyright (C) 2007 nixCraft project <http://www.cyberciti.biz/tips/contact-us> 
# This script is licensed under GNU GPL version 2.0 or above 
# ------------------------------------------------------------------------- 
# This script is part of nixCraft shell script collection (NSSC) 
# Visit http://bash.cyberciti.biz/ for more information. 
# http://bash.cyberciti.biz/file-management/awk-array-script-to-find-file-maximum-minimum-and-total-file-sizes/ 
# ------------------------------------------------------------------------- 
 
dirs="$@" 
 
[ $# -eq 0 ] && { echo "Usage: $0 dir1 dir2 dir N"; exit 999; } 
 
for d in $dirs 
do 
	[ ! -d $d ] && { echo "** Error: $d is not directory"; continue; }  
 
	echo "*** Info for $d directory ***" 
	ls -Al $d | egrep -wv "^total"  |awk 'BEGIN{c=0;max=0;min=0;total=0} 
 
			{arr[c]=$5;c++;total+=$5} 
 
			END{ 
				  for (x = 0; x <= (c-1); x++){ 
				        if ( arr[x] > max ) max = arr[x]; 
  				   } 
				   min=max; 
				  for (x = 0; x <= (c-1); x++){ 
				        if ( arr[x] < min ) min = arr[x]; 
  				   } 
			print "Max size:",max, "\nMin size:", min, "\nTotal size:", total}' 
done
/home1/yepnnet/public_html/wiki/data/pages/awk.txt · 最后更改: 2010/06/02 20:04 由 admin
到顶部
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0