New to PowerShell and trying hard to get something out of the text file.
Here is sample data:
RDFC1111 Z MED 22 23:18:39 MPHSFHFKD OF THE AAAOAAAY GAAAAAA~ PAGE; 1
DEFSDLSERD FSGHS CONRFGL CEERTE
ASDF DFGF ASDA ERDFG REEVHT
QWERTY SDFGTE: 3160 - ASDMPBVC FGHJINCIAL OFGTFDSS
JHGTR ------- ASDV---------- FIELD IN ERROR ERROR DESCRIPTION
TYPE JINYNGT HJUBGD N[ID7BER CRT JUR YR INFORMATION NJHGJVGFW -------------------- ---------------------
PD31 MK56502 3160 311 50 02156334001 LOPJUT SURPKJH
„ ERROR MESSAGE LOPJUT PKJH IS MANDATORY
PD31 CD15622 3160 311 50 03214114001 LOPJUT ADDRESS - STREET
„ ERROR MESSAGE LOPJUT ADDRESS IS MANDATORY
PD31 AK12102 3160 311 50 02652224001 LOPJUT ADDRESS - CITY
„ ERROR MESSAGE LOPJUT ADDRESS IS MANDATORY
PD31 A4833-00009-61001 HJPOOL 3160 311 50 06585527001 LOPJUT GIVEN PKJH
AKASHDEEP „ ERROR MESSAGE LOPJUT PKJH IS MANDATORY
PD31 A5709-00000-00322 RAAK 3160 311 50 02197133001 LOPJUT GIVEN PKJH
AMANDEEP „ ERROR MESSAGE LOPJUT PKJH IS MFiNDATORY
PD31 A4781-00009-90503 NUMJ13 3160 311 50 05501950001 LOPJUT GIVEN PKJH
AJAYKARPN „ ERROR MESSAGE LOPJUT PKJH IS MANDATORY
~#~ 3~ ~•~5~ 9~4 -~o aa<a•„webnuai u~,~~~L Lt~«<.uc ~,
- w
J, _
si~_o_. ,.._,~r~':L _ ~r.;~~n< r~~ n~in:~r~~P t+m5'1' P~ EQ~rc~. 'r0 ~S~ta`~I~ 7
PD31 50394-00008-80406 AY51619 3160 311 50 02177107001 LOPJUT GIVEN PKJH
I'm trying to extract the bold fields from each line.
The output I'm looking for:
MK12001 C2100123
MK13103 C2100124
MRDOOP C21005237
JPPK C2123133
What I'm getting currently:
MK12001 3160
C2100123
MK13103 3160
C2100124
MRDOOP 3160
C21005237
JPPK 3160
C2123133
Problem:
Because I'm using "3160" for my match criteria for my first field so it's showing up in the results as well and for my second field which is a ticket# (C1234567), due to the use of "pipe" operator or "second" search/match criteria its going in the next line, If someone can help me to keep the ticket # in the same field then I guess I can live with having "3160" in between so it will look like
MK12001 3160 C2100123
or if someone can suggest me to only display the bold fields i.e before the 3160 then that would be awesome.
MK12001 C2100123
P.S: with my script, I'm already changing the "0" to "C" in ticket # field (C1234567)
Here is the code so far:
#Location of original file
$Location = "C:\Temp\Ap8.txt"
#Location of file where the "0" is replaced with "C"
$Location2 = "C:\Temp\results9.txt"
#Final results
$Location3 = "C:\Temp\tickets9.txt"
#get the original file
$Change = Get-Content $Location
# replace C with 0
$Change | ForEach-Object {$_ -Replace "3160 311 50 0", "3160 311 50 C"} |
#write the results to staging file
Set-Content $Location2
#get the staging/udpated file
Get-Content $Location2 -Raw |
#look up for a specific fileds, I have to fetch two fields from each line therefore using pipe operator inbetween
Select-String "\s\w{1,8}\s3160| C\d{7}" -AllMatches |
% { $_.Matches.Groups.Value } |
Out-File $Location3 -Encoding ascii -Force
RD32and3160are constant values and what you're looking for, for the first match is between these constants? And for the second match, can we assume it's always a 8 numeric digits value followed by001?MFiNDATORY) ? Please open it in notepad. Copy a couple of lines and paste it in your question