Unix_and_AWK_Guide
Unix_and_AWK_Guide
1. Unix Basics
Unix is a powerful, multiuser, multitasking operating system used for servers, desktops, and
laptops. Here are some essential Unix commands and concepts:
3. File Permissions:
- chmod: Change file permissions (e.g., chmod 755 script.sh)
- chown: Change file ownership
4. Process Management:
- ps: Show current processes
- top: Dynamic view of processes
- kill: Terminate process (e.g., kill 1234)
AWK is a powerful text-processing tool. It scans files line by line, splits each line into fields,
and performs actions.
Syntax:
awk 'pattern { action }' filename
- FS: Field Separator (default is space; set to '@' for your data)
- NR: Current Record Number (line number)
- $1, $2, ..., $n: Represents fields in a line
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Q5: Count HR employees
Command:
awk -F@ 'NR > 1 && $4=="HR" { count++ } END { print count }' employees.txt
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Q10: Salary incremented by 10%
Command:
awk -F@ 'NR > 1 { inc = $5 * 1.10; print $2, inc }' employees.txt
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Q15: Names containing 'y'
Command:
awk -F@ 'NR > 1 && $2 ~ /y/ { print $2 }' employees.txt
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.
Explanation:
This command sets '@' as field separator and processes the file line-by-line according to the
condition specified.