Program to add word(s) to each line in another list of words?

Status
Not open for further replies.

camosilver311

In Runtime
Messages
140
I have several text files of keyword lists generated for each landing page that I am promoting through pay per click advertising for my website. However, I also want to add specific cities, counties, and states to my keyword lists. This could be done in some instances with the find/replace function of notepad, but I don't think this will work for me in this case. Here's why:

Example:

Lets say I have the following list of keywords:

widgets
find widgets
search widgets
lookup widgets
widgets lookup
widget search

I have a list of every state and every county in the US, and I want to create additional keywords from this list that include every state and every county in the US for each keyword in my list. So, for example, this list would start to look like this:

alaska widgets
alabama widgets
arkansas widgets
etc

Abbeville County widgets
Acadia Parish widgets
Accomack County widgets
etc

alaska find widgets
alabama find widgets
arkansas find widgets
etc

Abbeville County find widgets
Acadia Parish find widgets
Accomack County find widgets
etc

So you can see that each one keyword would have an additional 50 keywords generated just from the states, not to mention many more for each US county.

I am looking for a tool that can take a list of keywords and take another list of words I choose(the states and counties), and add the states and counties to each keyword in the list. It should be able to insert the states/counties at the beginning or end of the original keyword.

Hopefully this makes sense and you can see why replace will not work here. Any suggestion on how I can do what I am looking to do?
 
I would say move this to the programming section and ask someone to help you write a script for this

As I know it isn't that hard to have a script add a word to lets say the start of each line in a text document and have it output this as a different file name.

So if you had your list of places you could run the script and it would generate a file which had the keyword+place on each line
Then you would need an additional bit of script to then add this into your current text files

I am a novice at writing scripts, I could make something like this but it would take me a lot longer than someone who programs all the time.

I would also say maybe offer an incentive as this iappears to be a work based task and one that I can only assume is helping you make money, so it would only be fair to help out the person who could write this for/with you
 
I would say move this to the programming section and ask someone to help you write a script for this

As I know it isn't that hard to have a script add a word to lets say the start of each line in a text document and have it output this as a different file name.

So if you had your list of places you could run the script and it would generate a file which had the keyword+place on each line
Then you would need an additional bit of script to then add this into your current text files

I am a novice at writing scripts, I could make something like this but it would take me a lot longer than someone who programs all the time.

I would also say maybe offer an incentive as this iappears to be a work based task and one that I can only assume is helping you make money, so it would only be fair to help out the person who could write this for/with you

Tanks for the reply. I'll consider hiring a freelancer to create a script as a last resort. I find it hard to believe that such a program doesn't already exist, seems like something that many other people have had a need for, and there should already be something floating around the net that does this. It's hard to search for something like this because I don't know exactly what to call this process.
 
thanks again for the reply. i've never messed with linux and honestly didn't want to put too much effort into this. i guess i'll just forget about this for now. what a shame.
 
I'd help but I'm a little confused as to exactly how you want this to work. Are you saying you have a list of keywords, a list of counties, and a list of countries, and you want a program that will output a list of all the combinations possible with the keywords being in the middle, and the county/country being either on one side or the other, or both even?
Are the lists organised at all in any particular way?
 
I'd help but I'm a little confused as to exactly how you want this to work. Are you saying you have a list of keywords, a list of counties, and a list of countries, and you want a program that will output a list of all the combinations possible with the keywords being in the middle, and the county/country being either on one side or the other, or both even?
Are the lists organised at all in any particular way?

Sorry, it's kinda hard explaining exactly what I am trying to do. I have a list of every state and county in the US. For now, let's just use the county list. An example of a few lines of the county list is as follows:

Accomack County, Virginia
Ada County, Idaho
Adair County: IA; KY; MO; OK
Adams County: CO; ID; IL; IN; IA; MS; NE; ND; OH; PA; WA; WI
Addison County, Vermont
Aiken County, South Carolina
Aitkin County, Minnesota

I need to remove everything after the word "county". Once I do this, it's easy to go into notepad and use the find/replace function to find "county" and replace with "county keyword". I just need to figure out how to remove everything after "county".

I have google searched this but I don't understand the process involved as I do not know anything about scripts, coding, programing, etc. I have some basic html knowledge and that's it. For example, I went to this site, regex - remove all characters after pattern in text file - Stack Overflow, and it looks like someone is trying to do something similar to me. People replied with examples of some sort of code, but I have no idea what to do with it. Every single site I found that people had asked this type of question, people replied with some sort of code but nobody explained how to use it.

Hopefully this is making more sense. Thanks for any help.
 
I've got an Episode of Eureka to watch now, then I'll be hitting the hay. But if you can't figure it out before I get back, I'll have a look at this tomorrow for you. Check back in 15 hours if you need it I guess lol. Shouldn't be complicated, what kmote said will probably work :p
 
To answer the question about what to do with the code on Stackoverflow: the OP there is using vim which is a text editor primarily on *nix platforms but also available in some form on windows. I wouldn't recommend that path for you, this is an easy task in notepad++.

I've just tested the provided sample data and the only regex I needed was
Find what: County.*
Replace with: County

To get the "cartesian product" of the two lists eg.

list 1
Accomack County
Ada County
Adair County
Adams County
Addison County
Aiken County
Aitkin County

list 2
widgets
find widgets
search widgets
lookup widgets
widgets lookup
widget search

You can use a spreadsheet application (I'm using Gnumeric)
1) Paste one list into a column (start in cell A2)
2) Use paste special -> transpose to paste the other list as a row (start in cell B1)
3) You now effectively have a matrix, in cell B2 enter =concatenate($A2," ",B$1) into the formula bar
4) The result of this should be "Accomack County widgets"
5) Drag down to autocomplete the first column
6) Highlight the contents of the first column and drag sideways to autocomplete the matrix
7) Highlight the contents of the matrix and paste this into notepad++
8) Use notepad++ find and replace in extended mode
Find what: \t
Replace with: \n

End result:
Accomack County widgets
Accomack County find widgets
Accomack County search widgets
Accomack County lookup widgets
Accomack County widgets lookup
Accomack County widget search
Ada County widgets
Ada County find widgets
Ada County search widgets
Ada County lookup widgets
Ada County widgets lookup
Ada County widget search
Adair County widgets
Adair County find widgets
Adair County search widgets
Adair County lookup widgets
Adair County widgets lookup
Adair County widget search
Adams County widgets
Adams County find widgets
Adams County search widgets
Adams County lookup widgets
Adams County widgets lookup
Adams County widget search
Addison County widgets
Addison County find widgets
Addison County search widgets
Addison County lookup widgets
Addison County widgets lookup
Addison County widget search
Aiken County widgets
Aiken County find widgets
Aiken County search widgets
Aiken County lookup widgets
Aiken County widgets lookup
Aiken County widget search
Aitkin County widgets
Aitkin County find widgets
Aitkin County search widgets
Aitkin County lookup widgets
Aitkin County widgets lookup
Aitkin County widget search
 
Status
Not open for further replies.
Back
Top Bottom