Content added Content deleted
imported>mutante mNo edit summary |
imported>mutante m (AwkPatternMatching moved to Awk pattern matching) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
AWK its big ... a full on |
[[Awk|AWK]] its big ... a full on [[:Category:Programming Languages|programming language]] really |
||
a GooD place to get more info is in the standard *nix |
a GooD place to get more info is in the standard *nix 'man' command |
||
---- |
---- |
||
Examples |
Examples |
||
Line 44: | Line 44: | ||
</pre> |
</pre> |
||
also see: [[Awk]] |
|||
[[Category:Linux]] |
[[Category:Linux]] |
||
[[Category:Computer]] |
[[Category:Computer]] |
||
[[Category:Unix]] |
[[Category:Unix]] |
||
[[Category:Programming Languages]] |
Latest revision as of 21:28, 29 March 2006
AWK its big ... a full on programming language really
a GooD place to get more info is in the standard *nix 'man' command
Examples
to make a list of all the users and shell's that are in use on your box (not a verry practical example as there are non user enrtys in your passwd file but...)
cat /etc/passwd | awk -F: ' {print $1 " " $7 }'
Explanation
-F: = use : as the separator ie use -F, for a csv file awk uses a space as standard print = print to StdOut $1 = the first varible found... " " = a space... well any string $7 = the 7th varible found
This example is nice in a file ... it will serch through InPut.txt and put all lines that match into OutPut.txt...
#!/bin/ksh awk -F, ' { if ( $2 ~ /^StartString/ && $2 ~ /EndString$/ ) { print $2 } } ' InPut.txt > OutPut.txt Explanation -F = as above use , as separator if = well standard programing stuff really, if (this is true) { then do this} $2 = 2nd varible ~ = regexe ie patern matching ( ^ = start of varible $ = end of string ) && = logical and (for strings) basicly, if $2 starts with StartString and ends with EndString then print it out...
also see: Awk