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
This should do it:
UPDATED: