Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have 1 large xml file with lines like -

<text file name 5 HD text>
<text file name 2 text>
<text file name 3 text>
<text file name HD 2 text>
<text file name 5 text>

Is possible using vbscript or powershell to output -

<text file name 5 HD text>
<text file name 3 text>
<text file name HD 2 text>

and in new file add lines being deleted -

<text file name 2 text>
<text file name 5 text>

HD is anywhere in file name and no sorting.

I find Deleting entire lines in a text file based on a partial string match with Windows PowerShell but is not exact answer. No Java per favore as I remove this for hacking safety.

share|improve this question
What's the rule for what goes into each file? It's not every other nor is lines containing "HD", nor is it odd versus even numbers. – Nicole Hamilton Jan 28 '13 at 5:42
@NicoleHamilton: Sorry please I no understand what you say. Some file names are there 2 times, 1 normal and 1 HD version. I want to remove normal version line to new file if HD version is there. If no HD then normal version is remaining in original xml. – Angelo Jan 28 '13 at 17:21

Simple script to separate lines into different files based on arbitrary criteria (such as if HD tag is there)

# Get the contents of the file.
$file = get-content ~\file.xml

# Loop through the xml file adding all "HD" tags to one file and all non "HD" tags to another file
foreach($text in $file)
    if($text.Contains("HD")) {
        Add-Content ~\hd.txt $text
    else {
        Add-Content ~\nohd.txt $text

If the criteria is a little different, then just change the "if" statement to suit your purposes.

share|improve this answer
Thank you for program, but is vbscript? powershell? Please help how to run? I think program will put HD file lines and normal file lines in 2 different files? but I want xml to have final list with HD if is there, and normal if no HD is there. new file must have only file lines deleted from xml. – Angelo Jan 28 '13 at 17:25
Sorry @Angelo, this is PowerShell. You're right about the script placing things in two different files. Do you mean you want the current XML to keep the HD files? And then a separate file with Deleted Code? If so, please see my edit – malgca Jan 28 '13 at 17:37
No sorry please, is ok. I explain to nicole above - some files are having normal and HD version, some are only normal no HD. If 2 version, I want only HD in xml and normal in new file. If 1 version only - normal or HD - I want in xml like before. – Angelo Jan 28 '13 at 17:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.