Before I added the else if/else, when i only just had the:
if (/Easy: /) .. part
The program would launch when I put awk -f oscp-notes.awk and then put input, &c.
It would then print out appropriate Easy machines; however, after I added the else if section.
It will not print either easy or medium machines now. I do not have any errors. I figured that I needed to close(file) so I could re-read. I am stuck. I would like to be able to read/close and make rest of conditional statements to include user input whether it is easy/medium/hard/insane. Is this possible?
Edit: I have also tried close(file) instead of close("TJnulls.txt").
BEGIN {
printf "Please select a chapter by entering chapter number: "
getline entry < "-"
$2 == entry
file = "TJnulls.txt"
Test if statement
if (entry == 2) {
printf "Please select difficulty (easy, medium, hard, insane): "
getline difficulty < "-"
$3 == difficulty
if (difficulty == easy) {
{print "\n"}
{print "Obtaining the list of easy machines:\n"}
while (( getline<file) > 0) {
if (/Easy: /) {
{print $2};
} else {
close("TJnulls.txt");
break;
}
}
} else if (difficulty == medium) {
{print "\n"}
{print "Obtaining the list of medium machines:\n"}
while ( ( getline<file) > 0) {
if (/Medium: /)
{print $2}
}
}
}
}
EDIT: I have tried doing the following:
Use a for loop, with if conditions to a for loop and if conditions.
BEGIN {
printf "Please select a chapter by entering chapter number: "
getline entry < "-"
# For loop
i = 0;
{
for (i=1; i <= 11; i++) {
if ( ( entry == i ) &&
( i == 2 ) )
file = "TJnulls.txt"
{print "\nPlease select a difficulty:\n (easy=1, medium=2, hard=3, insane=4, menu=0)\n"}
getline difficulty < "-"
x = 0;
for (x=1; x <= 4; x++) {
if ( ( difficulty == x ) &&
( x == 1 ) )
file = "TJnulls.txt"
while ( (getline<file) > 0 ) {
if (/Easy: /)
{print $2}
}
if ( ( difficulty == i ) &&
( x == 2 ) )
file2 = "TJnulls.txt"
while ( (getline<file2) > 0 ) {
if (/Medium: /)
{print $2}
}
}
}
}
}
The problem is that it gives me an error:
18: fatal: expression for `<' redirection has null string value
Also, when I removed the file - variable (the first one) it would bark at me.