1
votes

I am stuck at a conversion of text file into csv where selected data needs to be put inside that csv. So far I have managed only one line of code that works for me and I am unable to take it further.

Text file:

Search: Object: EMP NAMES under /USER/ENT/FOL1

Object: EMP NAMES Object Location Point Alias EMP name
1SIG_MOU_RM_CTL /USER/ENT/BASE/FOL1
1SIG_MOU_COMBINED_ADJ /USER/ENT/BASE/FOL1
1SIG_MOU_CONTROL /USER/ENT/BASE/FOL1
1SIG_MOU_BKR /USER/ENT/BASE/FOL1
1SIG_MOU_MAN_ADJ /USER/ENT/BASE/FOL1
1SIG_MOU_PSS /USER/ENT/BASE/FOL1
1SIG_MOU_REG_MODE /USER/ENT/BASE/FOL1
SIG_MOUD_TUNE /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_41CONT /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_AUT_MD /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_BASE_MODE /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_FC1CTRL /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_FC2CTRL /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_PSS_MODE /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_SS_SIG_FIFO /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_SS_FCR_FIFO /USER/ENT/BASE/FOL1 BOARD
SIG_MOU_SP_TYPE /USER/ENT/BASE/FOL1 BOARD
SIG_MAST_BA_CONT /USER/ENT/BASE/FOL1 MVAR
SIG_ST_BE_ALG /USER/ENT/BASE/FOL1 VALPROF

SIG_SP_SIG_VALPROF /USER/ENT/BASE/FOL1 VALPROF

SIG_SP_FCR_VALPROF /USER/ENT/BASE/FOL1 VALPROF

SIG_TRANSFER_MOD_DC_SP /USER/ENT/BASE/FOL1 RELOC
LVR_MOU_MODULE_CMDS /USER/ENT/BASE/FOL1 BOARD
FCN0001 /USER/ENT/BASE/FOL1/Work Area 5/0001 FCN0001_900 SWEEP
FCN0001001 /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN0001005 /USER/ENT/BASE/FOL1/Work Area 5/0001 BOARD
FCN0001008 /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN000100A /USER/ENT/BASE/FOL1/Work Area 5/0001 BOARD
FCN000100C /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN000100E /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN0001010 /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN0001012 /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN0001018 /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN000101C /USER/ENT/BASE/FOL1/Work Area 5/0001 BIFOLD
FCN0001020 /USER/ENT/BASE/FOL1/Work Area 5/0001 CHANGEOVER
FCN0001028 /USER/ENT/BASE/FOL1/Work Area 5/0001 HOLD
FCN0001029 /USER/ENT/BASE/FOL1/Work Area 5/0001 HOLD
FCN000102A /USER/ENT/BASE/FOL1/Work Area 5/0001 HOLD
FCN0002 /USER/ENT/BASE/FOL1/Work Area 5/0002 FCN0002_901 SWEEP
FCN0002001 /USER/ENT/BASE/FOL1/Work Area 5/0002 CLONE
FCN000200B /USER/ENT/BASE/FOL1/Work Area 5/0002 CLONE
FCN000200D /USER/ENT/BASE/FOL1/Work Area 5/0002 CLONE
FCN0002013 /USER/ENT/BASE/FOL1/Work Area 5/0002 CLONE
FCN0002017 /USER/ENT/BASE/FOL1/Work Area 5/0002 CLONE
FCN0002019 /USER/ENT/BASE/FOL1/Work Area 5/0002 CLONE
FCN000201B /USER/ENT/BASE/FOL1/Work Area 5/0002 CLONE
FCN0003 /USER/ENT/BASE/FOL1/Work Area 3/0003 FCN0003_301 SWEEP
FCN0003010 /USER/ENT/BASE/FOL1/Work Area 3/0003 BIFOLD
FCN0003016 /USER/ENT/BASE/FOL1/Work Area 3/0003 SINGLE
FCN0004 /USER/ENT/BASE/FOL1/Work Area 2/0004 FCN0004_064 SWEEP
FCN0004005 /USER/ENT/BASE/FOL1/Work Area 2/0004 QUALITY FCN0004006 /USER/ENT/BASE/FOL1/Work Area 2/0004 QUALITY FCN0005 /USER/ENT/BASE/FOL1/Work Area 3/0005 FCN0005_201 SWEEP
FCN0005007 /USER/ENT/BASE/FOL1/Work Area 3/0005 SINGLE
FCN0005008 /USER/ENT/BASE/FOL1/Work Area 3/0005 SINGLE
FCN000500A /USER/ENT/BASE/FOL1/Work Area 3/0005 SINGLE
FCN0005010 /USER/ENT/BASE/FOL1/Work Area 3/0005 SINGLE
FCN0005023 /USER/ENT/BASE/FOL1/Work Area 3/0005 SINGLE
FCN0006 /USER/ENT/BASE/FOL1/Work Area 3/0006 FCN0006_204 SWEEP
FCN0006002 /USER/ENT/BASE/FOL1/Work Area 3/0006 BIFOLD
FCN0006007 /USER/ENT/BASE/FOL1/Work Area 3/0006 HOLD
FCN0006012 /USER/ENT/BASE/FOL1/Work Area 3/0006 BIFOLD
FCN0006014 /USER/ENT/BASE/FOL1/Work Area 3/0006 LOW FCN0007 /USER/ENT/BASE/FOL1/Work Area 5/0007 FCN0007_160 SWEEP
FCN0008 /USER/ENT/BASE/FOL1/Work Area 5/0008 FCN0008_161 SWEEP
FCN0009 /USER/ENT/BASE/FOL1/Work Area 3/0009 FCN0009_303 SWEEP
FCN0009001 /USER/ENT/BASE/FOL1/Work Area 3/0009 SEQ FCN0009016 /USER/ENT/BASE/FOL1/Work Area 3/0009 LOW FCN0009017 /USER/ENT/BASE/FOL1/Work Area 3/0009 SUM FCN000901C /USER/ENT/BASE/FOL1/Work Area 3/0009 CLONE
FCN000901D /USER/ENT/BASE/FOL1/Work Area 3/0009 OFI FCN000901F /USER/ENT/BASE/FOL1/Work Area 3/0009 SINGLE
FCN0009026 /USER/ENT/BASE/FOL1/Work Area 3/0009 SINGLE
FCN0009029 /USER/ENT/BASE/FOL1/Work Area 3/0009 SINGLE
FCN000902E /USER/ENT/BASE/FOL1/Work Area 3/0009 HIGHMON FCN0009036 /USER/ENT/BASE/FOL1/Work Area 3/0009 HIGHMON FCN0009038 /USER/ENT/BASE/FOL1/Work Area 3/0009 SINGLE
FCN0009039 /USER/ENT/BASE/FOL1/Work Area 3/0009 HIGHMON FCN000903A /USER/ENT/BASE/FOL1/Work Area 3/0009 SUM FCN000903B /USER/ENT/BASE/FOL1/Work Area 3/0009 HIGHMON FCN000903C /USER/ENT/BASE/FOL1/Work Area 3/0009 SINGLE
FCN000903D /USER/ENT/BASE/FOL1/Work Area 3/0009 SUM FCN000903E /USER/ENT/BASE/FOL1/Work Area 3/0009 HIGHMON FCN0009043 /USER/ENT/BASE/FOL1/Work Area 3/0009 SINGLE
FCN000904C /USER/ENT/BASE/FOL1/Work Area 3/0009 HOLD
FCN000904D /USER/ENT/BASE/FOL1/Work Area 3/0009 HOLD
FCN000904E /USER/ENT/BASE/FOL1/Work Area 3/0009 HOLD
FCN000904F /USER/ENT/BASE/FOL1/Work Area 3/0009 HIGH
FCN0009050 /USER/ENT/BASE/FOL1/Work Area 3/0009 GAIN
FCN0009051 /USER/ENT/BASE/FOL1/Work Area 3/0009 SINGLE
FCN000A /USER/ENT/BASE/FOL1/Work Area 5/000A FCN000A_150 SWEEP
FCN000A001 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A003 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A005 /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD
FCN000A006 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A008 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A00A /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD
FCN000A00D /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD
FCN000A00E /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A010 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A012 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A014 /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD
FCN000A017 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A019 /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD
FCN000A01C /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A01E /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A020 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A022 /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD
FCN000A025 /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD
FCN000A027 /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A02C /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A02D /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A02F /USER/ENT/BASE/FOL1/Work Area 5/000A CLONE
FCN000A03A /USER/ENT/BASE/FOL1/Work Area 5/000A BIFOLD

So far I am able to read the specific data using:

$a = (Get-Content *.txt) | Select-String "ValProf" , "BIFOLD" , "BOARD" | FOREACH {$_ -replace '/User/ENT/Base/'

        [array]$obj += New-Object psobject -Property @{

                 EMP = "Value in first column"
                Name  = "value in second column"


}
}
$a | Select-Object EMP , Name  | Export-Csv Output.csv -NoTypeInformation

The intended output will be in a csv format with 2 column headings EMP and Name. EMP shall contain SIG_MOUD_TUNE and Name shall contain BOARD. The output what i am trying to get is :- The output

1

1 Answers

1
votes

You are almost there. Instead of -split you could use the -replace function:

Get-Content *.txt | 
    Select-String "HSarna"  , "ValProf"  | 
    ForEach-Object {$_ -replace '/User/ENT/Base/'}

Edit: Based on your new requirements, here the code you need:

Get-Content *.txt |
    Select-String "ValProf" , "BIFOLD" , "BOARD" | 
    ForEach-Object {
        New-Object psobject -Property @{
                EMP = [regex]::Match($_, '(\w+)').Groups[1].Value
                Name  = [regex]::Match($_, '.*\s+(\w+)$').Groups[1].Value
        }
    }  | 
    Select-Object EMP , Name |
    Export-Csv Output.csv -NoTypeInformation