Open Source Desktop Environment : GnuAwk

HomePage :: Categories :: PageIndex :: RecentChanges
Search this site: OSDE.INFO is produced by "osde8info" :
http://www.gnu.org/software/gawk/manual/gawk.html
http://docs.freebsd.org/info/gawk/gawk.info.String_Functions.html

GNU awk


reverse
Use awk to print first three (space delimited) fields of a file in reverse order
$ awk '{print $3,$2,$1}' aaa.log


passthrough
Use awk to pass thru # comment lines and print first three (space delimited) fields of a file
$ awk '/^#/ {print} !/^#/ {print $1,$2,$3}' aaa.log | head


gsub
replace fsf with free software foundation
$ awk '{ gsub(/fsf/, "free software foundation", $0); print $0 }'


break fields into lines
print fields 2 4 6 on separate lines and separate with a blank line
$ awk '{print $2 ; print $4 ; print $6 ; print "" }'


split
Use awk to pass thru # comment lines and print first middle part of domain name from 5th field
$ awk '/^#/ {print} !/^#/ { split($5,url,".") ; print $1,$3,url[2] }' aaa.log | head


split a split
Use awk to passthru comments, split uri (8th field) and print value of 21st parameter
$ awk '/^#/ {print} !/^#/ { split($8,url,"&") ; split(url[21],ip,"=") ; print ip[2] }' aaa.log | head


#Remark: DCS-p
#Software: WebTrends SmartSource Data Collector V8.0
#Version: 1.0
#Date: 2006-11-14 09:33:48
#Fields: date time c-ip cs-username cs-host cs-method cs-uri-stem cs-uri-query sc-status sc-bytes cs-version cs(User-Agent) cs(Cookie) cs(Referer) dcs-id
10.10.10.10
10.10.10.10


awk script
/^#/ {print}
!/^#/ {
	n=split($4,params,"&")
	xips=params[n]
	
	n=split(xips,ips,"=")
	client=ips[n]
	
	n=split(client,ip,"+")
	if (n) {client=ip[n]}
	
	# gsub($3,client,$8)
	# gsub($3,client,$13)
	
	print $1,$2,client,$4,$5,$6
}

IN
x y z a=1&b=2&c=6 u v w
x y z a=1&b=2&c=3+4+5 u v w

OUT
x y 6 a=1&b=2&c=6 u v
x y 5 a=1&b=2&c=3+4+5 u v

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki
Page was generated in 0.0438 seconds