How to: egrep -n foo
awk '/foo/{print FNR,$0}' filename
```

###### Print the last column

```bash
awk '{print $NF}' filename
```

###### Find all the lines longer than 80 characters

```bash
awk 'length($0)>80{print FNR,$0}' filename
```

###### Print only lines of less than 80 characters

```bash
awk 'length < 80' filename
```

###### Print double new lines a file

```bash
awk '1; { print "" }' filename
```

###### Print line numbers

```bash
awk '{ print FNR "\t" $0 }' filename
awk '{ printf("%5d : %s\n", NR, $0) }' filename   # in a fancy manner
```

###### Print line numbers for only non-blank lines

```bash
awk 'NF { $0=++a " :" $0 }; { print }' filename
```

###### Print the line and the next two (i=5) lines after the line matching regexp

```bash
awk '/foo/{i=5+1;}{if(i){i--; print;}}' filename
```

###### Print the lines starting at the line matching 'server {' until the line matching '}'

```bash
awk '/server {/,/}/' filename
```

###### Print multiple columns with separators

```bash
awk -F' ' '{print "ip:\t" $2 "\n port:\t" $3' filename
```

###### Remove empty lines

```bash
awk 'NF > 0' filename