I'm taking my Linux+ midterm and I'm stuck on a question where I'm supposed to copy the head section including the tags and output it to a file. My midterm is due on the 5th so it would really help if someone showed me the correct code to use when greping for the head section and tags. I tried:  curl www.hackthissite.org: grep <head> > ~/data/public/myfirstname\ mylastname/head.txt but all it would say when I cat the file is<head>, doesn't include the head section or  tag. So what should I type to get the correct output to the file?
How to grab the head section of a website using the curl and grep command?
text processing;grep;curl;html
It's a bit more complex than what you're trying to do.First, there are some syntax issues on your command. This curl www.hackthissite.org: grep <head> > ~/data/public/myfirstname\ mylastname/head.txt should be:curl www.hackthissite.org | grep <head> > ~/data/public/myfirstname\ mylastname/head.txtBut even though it wouldn't do what you want, because you're only greping the head opening tag, but not what comes in between it and the closing tag.I came up with this:curl www.hackthissite.org > TEMPORARYFILE.txt; grep -A $(($(grep -n </head> TEMPORARYFILE.txt | cut -d: -f1) - $(grep -n <head> TEMPORARYFILE.txt | cut -d: -f1))) <head> TEMPORARYFILE.txt > ~/data/public/myfirstname\ mylastname/head.txt; rm TEMPORARYFILE.txtSo, by parts:grep -n </head> TEMPORARYFILE.txt | cut -d: -f1This will get the number of the line where the closing tag is. The same applies to grep -n <head> TEMPORARYFILE.txt | cut -d: -f1, but for the opening tag.Then we have $(($(grep -n </head> TEMPORARYFILE.txt | cut -d: -f1) - $(grep -n <head> TEMPORARYFILE.txt | cut -d: -f1))), which is supposed to calculate how many lines there are between the opening tag and the closing tag.This is used with the -A option of grep, which gives us control of how many lines after the match we want printed. So it will search for the opening head tag and print all the lines between it and the closing tag.