| 369 | |
| 370 | Awk is a scripting language used for manipulating data and generating reports. The awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators. |
| 371 | |
| 372 | Syntax: |
| 373 | |
| 374 | `awk options 'selection _criteria {action }' input-file > output-file` |
| 375 | |
| 376 | 1. Default behavior of Awk: By default Awk prints every line of data from the specified file. |
| 377 | |
| 378 | `$ awk '{print}' employee.txt` |
| 379 | |
| 380 | 2. Print the lines which match the given pattern. |
| 381 | |
| 382 | `$ awk '/manager/ {print}' employee.txt ` |
| 383 | |
| 384 | 3. Splitting a Line Into Fields : For each record i.e line, the awk command splits the record delimited by whitespace character by default and stores it in the $n variables. If the line has 4 words, it will be stored in $1, $2, $3 and $4 respectively. Also, $0 represents the whole line. |
| 385 | |
| 386 | `$ awk '{print $1,$4}' employee.txt` |
| 387 | |
| 388 | |
| 389 | |
| 390 | |
| 391 | |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | |
| 397 | |