From Fedora Project Wiki

Description

This test case aims to validate that gawk, a text processing utility, performs basic and some advanced operations correctly.

Setup

  1. Install gawk if not already installed using the command: sudo dnf install gawk

How to test

  1. Open a terminal window.
    1. Basic Operations
  2. Create a text file with some sample numbers. Run echo -e "1\n2\n3" > numbers.txt.
  3. Run a simple gawk command to sum the numbers in the file: gawk '{s+=$1} END {print s}' numbers.txt
  4. Run a gawk command to print the first field of each line in the file: gawk '{print $1}' numbers.txt
    1. Working with Text
  1. Create a text file with some sample text. Run echo -e "apple orange\nbanana grape" > fruits.txt.
  2. Use gawk to print only the first fruit from each line: gawk '{print $1}' fruits.txt
    1. Conditionals and Loops
  1. Use gawk to sum only the even numbers in 'numbers.txt': gawk '{if ($1 % 2 == 0) s+=$1} END {print s}' numbers.txt
  2. Use gawk to print each line from 'fruits.txt' with a line number: gawk '{print NR " " $0}' fruits.txt
    1. File Processing
  1. Use gawk to combine actions; print line number before lines containing 'apple' in 'fruits.txt': gawk '/apple/ {print NR " " $0}' fruits.txt

Expected Results

  1. The gawk package should install without errors.
  2. The first gawk command should output the sum of the numbers (in this case, "6").
  3. The second gawk command should print each number on a new line.
  4. The gawk command for printing the first fruit should output "apple" and "banana" on new lines.
  5. The conditional gawk command should correctly sum only the even numbers.
  6. Line numbers should be correctly printed before each line when using the NR variable.
  7. Only lines containing 'apple' should be printed with a line number before them.

Optional

For additional testing, you may try more complex gawk scripts to validate its functionality.