Jump to content

Best way to do foreach loop?


Recommended Posts

Here's what I'm wanting to do:

 

1. I'm going to manually edit a names.txt file (probably stored in dropbox) and each line will be an alphanumeric string

 

2. For each line in the names.txt I want to open a specific url (in safari or chrome) using the line in the text file as the query. eg: http://who.is/whois/{query}.com where query is the current line in my text file.

 

3. Repeat for each entry in names.txt.

 

How best to do this? I'm okay with bash/ksh scripts if that helps things.

 

Additionally, is there any way to capture the text contents of a webpage to a file so that I can subsequently grep for specific strings?

Link to comment

OS X has open, which will come in handy, here.

for line in $(cat "names.txt"); do
  open "http://who.is/whois/${line}.com"
done

 
Regarding your other question, you can do it via curl. Simply do something like curl http://example.com, and it’ll output the page directly to the terminal (from where you can pipe to grep directly). This is not necessarily a good idea, although It could be fine, depending on your needs.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...