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
- Install
gawk
if not already installed using the command:sudo dnf install gawk
How to test
- Open a terminal window.
- Basic Operations
- Create a text file with some sample numbers. Run
echo -e "1\n2\n3" > numbers.txt
. - Run a simple
gawk
command to sum the numbers in the file:gawk '{s+=$1} END {print s}' numbers.txt
- Run a
gawk
command to print the first field of each line in the file:gawk '{print $1}' numbers.txt
- Working with Text
- Create a text file with some sample text. Run
echo -e "apple orange\nbanana grape" > fruits.txt
. - Use
gawk
to print only the first fruit from each line:gawk '{print $1}' fruits.txt
- Conditionals and Loops
- Use
gawk
to sum only the even numbers in 'numbers.txt':gawk '{if ($1 % 2 == 0) s+=$1} END {print s}' numbers.txt
- Use
gawk
to print each line from 'fruits.txt' with a line number:gawk '{print NR " " $0}' fruits.txt
- File Processing
- Use
gawk
to combine actions; print line number before lines containing 'apple' in 'fruits.txt':gawk '/apple/ {print NR " " $0}' fruits.txt
Expected Results
- The
gawk
package should install without errors. - The first
gawk
command should output the sum of the numbers (in this case, "6"). - The second
gawk
command should print each number on a new line. - The
gawk
command for printing the first fruit should output "apple" and "banana" on new lines. - The conditional
gawk
command should correctly sum only the even numbers. - Line numbers should be correctly printed before each line when using the NR variable.
- 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.