16.05.2015 Views

Working with the Unix OS

Working with the Unix OS

Working with the Unix OS

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>Unix</strong> Tools<br />

BEGIN ( FS="\t" }<br />

{ $4 = 1000 * $3 / $2; print}<br />

# string concatenation<br />

/A/ { s = s" "$1 }<br />

END { print s }<br />

# arrays<br />

{ x[NR] = $0 }<br />

END { ... program ...}<br />

! Special Features<br />

Built-in Functions<br />

# print length of line<br />

{ print length $0 }<br />

# print country <strong>with</strong> longest name<br />

length($1) > max { max = length($1); name = $1 }<br />

END { print name }<br />

# abbreviate country names to 3 letters<br />

{ $1 = substr($1, 1, 3); print }<br />

Flow of Control<br />

{ if (maxpop < $3)<br />

{<br />

maxpop = $3<br />

country = $1<br />

}<br />

}<br />

END { print country, maxpop }<br />

{ i = 1<br />

while (i

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!