Delete lines with a script

I need to delete several lines in one operation based on several criteria. I know I can do it with only one crieria and I need three sentences but not with several and only one piece of code. For example I want to delete all lines that may content (name,street, city) any one of these names. One line may contain only the name, the other line may content only the city.

And how is that going for you?

Please add the code you have now, explain what you have tried and describe the errors you observe.

I only know how to code this
#elimina las líneas que contienen localhost
New-Item -ItemType file “file6.log” -force
Select-String ‘name’ .\file4.log -notmatch | % {$_.Line} | set-content file6.log

#elimina las líneas que contienen local
New-Item -ItemType file “file7.log” -force
Select-String ‘city’ .\file6.log -notmatch | % {$_.Line} | set-content file7.log

but I do like something like Select-String ‘name’ or ‘city’

If you read the Get-Help section on Select-String you can see that the Pattern parameter is an array of strings.

Select-String [-Pattern] <String[]> ...

This means that you can provide an array of strings to search for. In the examples help section for Select-String (the one you get if you run Get-Help Select-String -Examples) there is even an example of searching for any of two different strings:

-------------------------- EXAMPLE 7 --------------------------

PS C:\>select-string -path process.txt -pattern idle, svchost -notmatch

This command finds lines of text in the Process.txt file that do not include the words "idle" or "svchost".

Many thanks Robert. I will try. I used to code in visual basic years ago. No, retired, I am starting with Powershell to automate some code with a defined task. I should read the get-help first.Regards

The Get-Help in PowerShell is really wonderful. Both the Get-Help sections on each cmdlet which contain both documentation on the cmdlet and the cmdlet parameters as well as examples of usage. On top of that there are loads of Get-Help about_* sections (122 on my Win8.1 machine) which can be used for learning about powershell (e.g. about_WMI, about_scopes, about_Functions, about_Functions_Advanced). It’s a really good resource!

Thanks again. What I tried and got it with better or worse code is to automate the update of the HOSTS file based in two addresss. I just did it manually and with a task.And ¡It Works! The task is what matters.
here inclosed the text file with my project. It can help somebody else. I promise I will have a look to your references.Kind Regards Emilio

I also attach cabeza.txt

attached cabeza.txt

I can honestly say that I don’t understand your message. Is it working? Is it not working? If it isn’t, what is not working and what errors do you observe?

This also seems unrelated to the original reason for this thread. Could you please start a new discussion thread with a description of your new problem?

Yes Robert. The code you send me works very well and with it also the whole program. I just wanted to share the whole code for you to see. Kind regards. No other help needed for the moment.