Learn SQL by Building a Student Database: Part 1

Instructions: " It worked. Instead of printing the content, you can pipe that output into a while loop so you can go through the rows one at a time. It looks like this:

cat courses.csv | while read MAJOR COURSE
do
  <STATEMENTS>
done

Each new line will be read into the variables, MAJOR and COURSE. Add the above to your cat command. In the STATEMENTS area, use echo to print the MAJOR variable."

I have tried both the suggested code, which truncates the the major, and a revised code which removes the truncation. However, neither option allows me to proceed.

cat courses.csv | while read MAJOR COURSE
do
  echo "$MAJOR"
done
cat courses.csv | while IFS=, read -r MAJOR COURSE
do
  echo "$MAJOR"
done

Welcome to the forum @mcastillolewis

Try using IFS=","

The -r flag was not mentioned in the instructions.

Happy coding

Thanks for the quick reply, and appreciate the warm welcome! Unfortunately, using IFS=“,” did not solve the problem. The suggested solution (while read MAJOR COURSE) doesn’t print the full major, and using IFS seems to dissatisfy the check as well (although this allows the full major to print)

Please post your updated code.

cat courses.csv | while IFS="," read  MAJOR COURSE
do
  echo "$MAJOR"
done

Please remove the quote marks from the echo statement.

cat courses.csv | while IFS="," read  MAJOR COURSE
do
  echo  $MAJOR
done

No dice; this was not accepted as correct

The below is from the level. Even when copy and pasting exactly what the hint notes the solution should look like, it is not being accepted.

image

Try using just a single space between echo and the variable.

This is the output created when I input exactly what the second hint tells me to do.

image

To pass the level, I’m assuming it is looking for the code explicitly given in the hint (below). As shown in the screenshot above, it states “the whole loop should look like this”. However, this code does not generate the desired output (i.e. the non-truncated major names). My code above, using IFS, with or without quotations around the comma, generate the desired output, but does not pass the exercise.

cat courses.csv | while read MAJOR COURSE
do
  echo $MAJOR
done

Screenshot of output using IFS in the code:

image

Try without the internal field separator, and place four spaces before the echo statement.

Negative, that elicits the same output as screenshot above.

I understand that coding is a lot of banging your head into the wall to find a simple error, but at what point is this an issue with the lesson? I believe the default behavior is to truncate based on whitespaces, so the solution given in the “Hints” will not yield the correct output, and the lesson will not accept a solution that uses the internal field separator to specify the comma

Press the Reset button, enter the first line of code, them press Run multiple times to get back to where you were.

Thank you, I understand it too

Top reset or bottom reset? I have tried the bottom already.

image

I forgot there are two. Looks like the top one resets the current step.

However, if you reopen the project using the dashboard, perform the first task, you can press Run multiple times to get back to the current step.

For now try pressing the top Reset button.

Okay so at the CodeRoad screen of the project. Hit reset button it looks like multiple times? Or just hit reset once and then run the rest of the way? We still have to do the first exercise?

Press Reset once.
Do the first exercise.
Press Run multiple times.