Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell replace non matching entries
    primarykey
    data
    text
    <p>I have a powershell script that I am working on to edit some text files. So far I have managed to extract all the lines I want to edit using select string, then with some help from an earlier post I have managed to remove all of the information on each line that I don't need. What I want to do next is go through each line and remove any entries that do not match a particular string. So for example, the text file may contain the following entries:</p> <pre><code>"1.1.1.1" "2.2.2.2." "3.3.3.3" "4.4.4.4" "1.2.3.4" "1.2.3.4" "1.1.1.1" "2.2.2.2" "3.3.3.3" "4.4.4.4" </code></pre> <p>I want to strip out anything that isn't either "1.1.1.1" OR "2.2.2.2" OR "3.3.3.3" OR "4.4.4.4"</p> <ul> <li>All the entries are within double quotes</li> <li>The entries that need to be removed may be located anywhere on the line. </li> <li>The entries that need tobe removed differ on each line </li> <li>The entries that need to stay are fixed</li> </ul> <p><strong>Essentially, what I want to do is remove anything that does not match 1 of 6 possible fixed values and leave all other values unaffected.</strong></p> <p>Thus far I've tried using get-content with -replace option, various forms of select-string, regex etc but so far no luck. This is a little bit beyond my Powershell knowledge</p> <p>EDIT:</p> <p><strong>I think the original way I was trying wasn't the right way of going about it and perhaps I didnt phrase the question correctly. I now have all the entries in a csv file, the output of which is similar to the below:</strong></p> <pre><code>1 : Dhcp 2 : Server 3 : 192.168.0.1 4 : Scope 5 : 192.168.0.10 6 : set 7 : optionvalue 8 : 6 9 : IPADDRESS 10 : 192.168.0.11 11 : 192.168.0.12 12 : 192.168.0.13 13 : 192.168.0.14 14 : 192.168.0.15 15 : 192.168.0.16 16 : 192.168.0.17 17 : 18 : 19 : 20 : </code></pre> <p><strong>What I would like to do is go through the csv file, check the value of columns 10-16 for each entry, and delete any entries that do not match a predefined list.</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload