Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8194829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:56:51+00:00 2026-06-07T04:56:51+00:00

I have a text file which looks something like below, try to get meaningful

  • 0

I have a text file which looks something like below, try to get meaningful data by doing replace, using wild card characters, but not quite getting it right.

 computer  - server1
 Volume 1         System Rese  NTFS  junk data
 Volume 2     C                NTFS  junk data 
 Volume 3         R5T1_ABCDEF  NTFS    junk data
   H:\R5X1_ABCDEF99XY2_APP01_ABCD_LH\
 Volume 4     H   R5T1_ABCDEF  NTFS       junk data
 Volume 5         R5T1_ABCDEF  NTFS   junk data
   H:\R5X1_ABCDEF99XY2_DBE01_EFGH_LH\
 Volume 10         R6T3_ABCDEF  NTFS  junk data
   H:\R6X3_ABCDEF99XY2_QRS_IJKL_LH\
 Volume 7         R5T2_ABCDEF  NTFS   junk data
   H:\R5X2_ABCDEF99XY2_QWE__MNOP_LH\
 Volume 8         R5T1_ABCDEF  NTFS   junk data
   H:\R5X1_ABCDEF99XY2_BTE___0DF8_LH\
 computer  - server2
 Volume 1         System Rese  NTFS  junk data
 Volume 2     C                NTFS  junk data 
 Volume 3         R5T1_ABCDEF  NTFS    junk data
   H:\R5X1_ABCDEF88XY2_APP01_ABCD_LH\
 Volume 4     H   R5T1_ABCDEF  NTFS       junk data
 Volume 5         R5T1_ABCDEF  NTFS   junk data
   H:\R5X1_ABCDEF88XY2_DBE01_EFGH_LH\
 Volume 10         R6T3_ABCDEF  NTFS  junk data
   H:\R6X3_ABCDEF88XY2_QRS_IJKL_LH\
 Volume 7         R5T2_ABCDEF  NTFS   junk data
   H:\R5X2_ABCDEF88XY2_QWE__MNOP_LH\
 Volume 8         R5T1_ABCDEF  NTFS   junk data
   H:\R5X1_ABCDEF88XY2_BTE___0DF8_LH\

This is the output I am looking for : 1) get those volumes with a letter next to them(like volumes 2,4).
2) get those volumes with no letter next to them, the line below it which is not a volume line (like volumes 3,5,6). 3) remove those volumes with no letter nor a non-volume line below them (like volume 1).

Eventually, output looks like:

computer1 Volume 2  C
computer1 Volume 3  H:\R5X1_ABCDEF99XY2_APP01_ABCD_LH\
computer1 Volume 4  H
computer1 Volume 5  H:\R5X1_ABCDEF99XY2_DBE01_EFGH_LH\
computer1 Volume 10 H:\R6X3_ABCDEF99XY2_QRS_IJKL_LH\
computer2 Volume 2  C
computer2 Volume 3  H:\R5X1_ABCDEF88XY2_APP01_ABCD_LH\
computer2 Volume 2  H
computer2 Volume 3  H:\R5X1_ABCDEF88XY2_DBE01_EFGH_LH\
computer2 Volume 4  H:\R6X3_ABCDEF88XY2_QRS_IJKL_LH\
computer2 Volume 10 H:\R6X3_ABCDEF88XY2_QRS_IJKL_LH\

Edit Example code from comment:

im a bit stuck on the conditions tht need to be used :

$FileListArray2 = @()
Foreach($file in Get-Content $FilesName | Where-Object {$_ -notmatch "(junk1)|(junk2)"}) { 
    if($file -match "(Volume)") { } 
    $FileListArray2 += ,@($file2) 
} 
$FileListArray2 

Please note that here I have left the condition bit empty, i have tried some stuff for that but its not quite working the way i want

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T04:56:54+00:00Added an answer on June 7, 2026 at 4:56 am

    This should do it:

    UPDATED:

    $inputstring = @'
     computer  - server1
     Volume 1         System Rese  NTFS  junk data
     Volume 2     C                NTFS  junk data 
     Volume 3         R5T1_ABCDEF  NTFS    junk data
       H:\R5X1_ABCDEF99XY2_APP01_ABCD_LH\
     Volume 4     H   R5T1_ABCDEF  NTFS       junk data
     Volume 5         R5T1_ABCDEF  NTFS   junk data
       H:\R5X1_ABCDEF99XY2_DBE01_EFGH_LH\
     Volume 10         R6T3_ABCDEF  NTFS  junk data
       H:\R6X3_ABCDEF99XY2_QRS_IJKL_LH\
     Volume 7         R5T2_ABCDEF  NTFS   junk data
       H:\R5X2_ABCDEF99XY2_QWE__MNOP_LH\
     Volume 8         R5T1_ABCDEF  NTFS   junk data
       H:\R5X1_ABCDEF99XY2_BTE___0DF8_LH\
     computer  - server2
     Volume 1         System Rese  NTFS  junk data
     Volume 2     C                NTFS  junk data 
     Volume 3         R5T1_ABCDEF  NTFS    junk data
       H:\R5X1_ABCDEF88XY2_APP01_ABCD_LH\
     Volume 4     H   R5T1_ABCDEF  NTFS       junk data
     Volume 5         R5T1_ABCDEF  NTFS   junk data
       H:\R5X1_ABCDEF88XY2_DBE01_EFGH_LH\
     Volume 10         R6T3_ABCDEF  NTFS  junk data
       H:\R6X3_ABCDEF88XY2_QRS_IJKL_LH\
     Volume 7         R5T2_ABCDEF  NTFS   junk data
       H:\R5X2_ABCDEF88XY2_QWE__MNOP_LH\
     Volume 8         R5T1_ABCDEF  NTFS   junk data
       H:\R5X1_ABCDEF88XY2_BTE___0DF8_LH\
    '@
    
    # Split the input into an array of strings
    $lines = $inputstring -split '[\r\n]'
    
    # Setup patterns to match against
    $pattern1 = "(Volume \d+)\s+(\w)\s+"
    $pattern2 = "(Volume \d+)\s+"
    $pattern3 = "\s+(\w:\\.*)"
    $pattern4 = "^ computer  - (\S+)$"
    
    # Store the current computer that is being viewed
    $currentcomputer = "UNKNOWN"
    
    # Loop through each line
    for($i = 0; $i -lt $lines.count; $i++)
    {
        # Start off assuming the current line produces no output
        $output = ""
    
        # Look for volumes with drive letters
        if($lines[$i] -match $pattern1)
        {
            $output = $matches[1] + " " + $matches[2]
        }
        # Look for volumes without drive letters
        elseif($lines[$i] -match $pattern2)
        {
            $volume = $matches[1]
    
            # Consider the next line to see if it has a path
            if($lines[$i + 1] -match $pattern3)
            {
                $output = $volume + " " + $matches[1]
    
                # If the next line had a path then we handled it and need to skip it
                $i++
            }
        }
        elseif($lines[$i] -match $pattern4)
        {
            $currentcomputer = $matches[1]
        }
    
        # Write out any output that was produced
        if($output -ne "")
        {
            $currentcomputer + " " + $output
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text file, which looks like this: node13 state = free np
I have a text file which has a particular line something like sometext sometext
I have a text file which contains something like this: Hello, my name is
So I have a a text file that looks something like this: public >ret
I have a Rails RSpec file which looks something like require 'spec_helper' describe Something
I have a large file (2GB) which looks something like this: >10GS_A YTVVYFPVRGRCAALRMLLADQGQSWKEEVVTVETWQEGSLKASCLYGQLPKFQDGD LTLYQSNTILRHLGRTLGLYGKDQQEAALVDMVNDGVEDLRCKYISLIYTNYEAGKD
I have a text file which I am reading and storing the data in
I have a text file which contains data seperated by '|'. I need to
I have a text file which I want to filter using awk. The text
I have a file structure on my server that looks something like this: My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.