InterviewPitch

Land the job you want — prepare
with Real interviews Q&A

Curated interview questions, company-wise guides and coding rounds. Practice mock interviews, improve with feedback, and track your progress.

Q&A
Top curated interview packs
Company-wise & role-wise packs, quality assured.
Mock interview
AI scoring
Coding rounds
Top 10 sets
Beginner
1. What is AWK?

AWK is a powerful text-processing, data-extraction, and pattern-scanning programming language that is standard on Unix and Linux-like operating systems. It works by checking lines of a file, matches particular pattern rules, and runs corresponding scripting instructions.

Beginner
2. Who developed AWK?

AWK was designed and implemented in 1977 by three legendary computer scientists: Alfred Aho, Peter Weinberger, and Brian Kernighan. The name of the language is an acronym derived from the first letters of their last names.

Beginner
3. What is the basic syntax of AWK?

The standard structure consists of a pattern definition followed by an action enclosed inside curly braces:

AWK
awk 'pattern { action }' file
Beginner
4. What is a pattern in AWK?

A pattern acts as a gatekeeper rule or filtering condition. AWK loops through input lines and runs actions only if a line matches the pattern (e.g., regex filters, numerical comparisons, or target words).

Beginner
5. What is an action in AWK?

An action is a sequence of statements enclosed in curly brackets { ... }. When a pattern is matched, AWK runs these statements (e.g., calculations, custom formatting, or text outputs).

Beginner
6. What does $0 represent?

In AWK, $0 is a special variable representing the entire current line of input record in its original un-split state:

AWK
awk '{ print $0 }' file.txt
Beginner
7. What does $1, $2 represent?

AWK splits records into column columns dynamically. $1 stores the first field, $2 is the second, and so on:

AWK
awk '{ print $1, $2 }' file.txt
Beginner
8. What is FS?

FS stands for Field Separator. It defines the character used to split incoming records into fields. The default FS is whitespace (spaces and tabs):

AWK
awk 'BEGIN { FS=":" } { print $1 }' file.txt
Beginner
9. What is OFS?

OFS stands for Output Field Separator. It specifies the delimiter used when printing fields separated by commas in print statements:

AWK
awk 'BEGIN { OFS=" | " } { print $1, $2 }' file.txt
Beginner
10. What is NR?

NR stands for Number of Records. It tracks the total count of lines processed so far, functioning like a current loop iteration counter:

AWK
awk '{ print NR, $0 }' file.txt
Beginner
11. What is NF?

NF is a built-in variable containing the Number of Fields in the current line record. It is highly useful for checking line complexity or printing specific end elements:

AWK
awk '{ print NF }' file.txt
Beginner
12. What is BEGIN block?

The BEGIN block represents an initialization phase. Statements placed inside a BEGIN block execute exactly once before AWK reads any lines of the input file:

AWK
awk 'BEGIN { print "Processing Start..." } { print $1 }' file.txt
Beginner
13. What is END block?

The END block runs exactly once after AWK has finished processing all lines of input records. It is typically used for printing final summaries, calculated totals, or averages:

AWK
awk '{ print $1 }' END { print "Total Lines Processed:", NR } file.txt
Beginner
14. How to print a file using AWK?

By default, calling print with no parameters outputs the entire current line record:

AWK
awk '{ print }' file.txt
Beginner
15. How to print specific column?

You can print targeted fields by passing variable indices like $1 or $2 directly to print commands:

AWK
awk '{ print $2 }' file.txt
Intermediate
16. How to set custom delimiter?

Use the -F command-line argument to specify a custom character string as the field delimiter:

AWK
awk -F',' '{ print $1, $3 }' file.csv
Intermediate
17. How to print lines containing a word?

Pass the word inside regular expression slashes (/pattern/) before the action execution block:

AWK
awk '/error/' file.txt
Intermediate
18. How to print lines greater than value?

Use comparison operators (>, <, ==) to evaluate field column values:

AWK
awk '$3 > 100' file.txt
Intermediate
19. How to count lines?

By outputting the final NR value inside an END block, you get the overall number of lines processed:

AWK
awk 'END { print NR }' file.txt
Intermediate
20. How to sum a column?

Accumulate column field values iteratively inside variables, then output the final calculation state in the END block:

AWK
awk '{ sum += $2 } END { print sum }' file.txt
Intermediate
21. How to print line numbers?

By printing the record variable NR alongside the original string $0, you get line numbers prefixing each record:

AWK
awk '{ print NR, $0 }' file.txt
Intermediate
22. How to print last field?

Access the final field element dynamically using $NF, which acts as a pointer index to the total number of fields:

AWK
awk '{ print $NF }' file.txt
Intermediate
23. How to replace text?

Use the built-in gsub() utility to swap matches globally on line strings:

AWK
awk '{ gsub(/old/, "new"); print }' file.txt
Intermediate
24. How to print even lines?

Check if the current line record number NR is divisible by 2 using modulus operations:

AWK
awk 'NR % 2 == 0' file.txt
Intermediate
25. How to print odd lines?

Filter line records using the modulus operation matching non-zero remainder states:

AWK
awk 'NR % 2 == 1' file.txt
Intermediate
26. What is RS?

RS is the Record Separator. It controls how input data is divided into logical records (default is newline \n). Setting RS to empty ("") enables multi-line paragraph parsing modes:

AWK
awk 'BEGIN { RS="" } { print $1 }' file.txt
Intermediate
27. How to use conditions?

Place string or numeric conditional checks as patterns before action blocks to selectively process lines:

AWK
awk '$2 == "Admin"' file.txt
Intermediate
28. How to use if statement?

Use standard if-else constructs inside action blocks to create branching logic paths:

AWK
awk '{ if ($3 > 50) print $1, "Passed"; else print $1, "Failed" }' file.txt
Intermediate
29. How to use loops?

Run standard loop loops (for, while) directly inside action blocks to parse field segments cleanly:

AWK
awk '{ for (i = 1; i <= NF; i++) print "Field", i, "is", $i }' file.txt
Intermediate
30. How to format output?

Use the formatting utility printf to configure tabular columns, padding alignments, and custom layouts:

AWK
awk '{ printf "%-10s %5d\n", $1, $2 }' file.txt
Intermediate
31. What is associative array?

An associative array is a map index system backed by string keys instead of numbers. This allows developers to build lookup structures matching terms, counts, or keys directly.

Intermediate
32. How to count duplicate values?

By mapping string values into associative arrays, you can easily track occurrence frequencies across fields:

AWK
awk '{ count[$1]++ } END { for (val in count) print val, count[val] }' file.txt
Intermediate
33. What is getline?

The getline function explicitly reads the next line of input immediately, allowing developers to control line iteration manually within custom control logic loops.

Intermediate
34. How to ignore case?

Configure the system variable IGNORECASE = 1 inside your BEGIN block to make regular expressions case-insensitive:

AWK
awk 'BEGIN { IGNORECASE = 1 } /error/' file.txt
Intermediate
35. How to print first and last line?

Check the record count NR for 1 to catch the first line, then run the END block to catch the final record:

AWK
awk 'NR == 1 { print "First:", $0 } END { print "Last:", $0 }' file.txt
Advanced
36. How to pass variables?

Use the -v argument flag to map shell environment variables into AWK parameters before script parsing begins:

AWK
awk -v threshold=100 '$3 > threshold' file.txt
Advanced
37. How to merge two files?

Track index states using NR == FNR to cache the first file in memory, then map values against the second target:

AWK
awk 'NR == FNR { a[$1] = $2; next } { print $0, a[$1] }' file1 file2
Advanced
38. What is gsub()?

The gsub() function performs string replacement globally across matched target strings. It modifies the variable parameter references directly in memory.

Advanced
39. What is sub()?

Unlike `gsub()`, the sub() function is non-global. It targets and replaces only the very first occurrence of a matched pattern on structural variables.

Advanced
40. How to delete empty lines?

By checking the field count variable NF, AWK automatically filters out and skips blank line inputs:

AWK
awk 'NF' file.txt
Coding Round
41. Print 2nd column sorted

Isolate column columns using AWK, then pass the pipe stream into the terminal utility sort:

AWK
awk '{ print $2 }' file.txt | sort
Coding Round
42. Find max value in column

Calculate maximum column values efficiently by running variable check bounds iteratively:

AWK
awk 'BEGIN { max = 0 } $3 > max { max = $3 } END { print "Max:", max }' file.txt
Coding Round
43. Reverse file content

Load all line strings sequentially into an array, then iterate backwards through the array in the END block:

AWK
awk '{ lines[NR] = $0 } END { for (i = NR; i >= 1; i--) print lines[i] }' file.txt
Coding Round
44. Remove duplicates

Filter repeating strings quickly using associative index increments with boolean patterns:

AWK
awk '!seen[$0]++' file.txt
Coding Round
45. Count words in file

Track dynamic word counts by accumulating the NF values of each input record:

AWK
awk '{ total += NF } END { print "Words:", total }' file.txt
Coding Round
46. Extract lines between patterns

Identify and output records belonging strictly between specific starting and ending pattern definitions:

AWK
awk '/start/,/end/' file.txt
Coding Round
47. Print CSV column

Split standard comma-separated inputs safely using custom field delimiters:

AWK
awk -F',' '{ print $2 }' file.csv
Coding Round
48. Replace delimiter

Swap delimiters globally by configuring matching variables inside BEGIN blocks:

AWK
awk 'BEGIN { FS=","; OFS="|" } { $1=$1; print }' file.csv
Coding Round
49. Count specific word

Parse fields iteratively across columns to match and count exact target words:

AWK
awk '{ for (i=1; i<=NF; i++) if ($i == "target") count++ } END { print "Occurrences:", count }' file.txt
Coding Round
50. Print unique first column

Map and isolate unique string parameters across columns while skipping repeated entries:

AWK
awk '!seen[$1]++ { print $1 }' file.txt