Hi there,
I am new in Powershell scripting, so sorry for the questions.
I am busy writing a script and need some help. I will try explaining step by step what I want to do:
- I am pulling data from a DB into a flat file (c:\temp\db.txt). The info what is in the file:
Output:
Submitted/Executing Jobs
ORDERID NAME TYPE ODATE PID RUNCNT
00000005|Test |FLD |20171201| |22 |
00000006|sleep |CMD |20171201|12688 |22 |
Result: Success.
- I now need to grab the one line and then grab the one column / string. I have defined doing this in Powershell, and here my line I use and I pump that into a flat file, c:\temp\output.txt:
- My command:
cat c:\temp\db.txt | where {$_-match “sleep”} > c:\temp\output.txt - output of the file:
00000006|sleep |CMD |20171201|12688 |22 |
Problem:
I need to grab now the first 8 characters on this line and pipe it to a variable which I will then use to execute an external command using this variable.
I tried the following: (I use output file to see if I pass the correct information - I need ot pass it as a variable)
cat c:\temp\db.txt | where {$-match “sleep”} | foreach{$.split()[0]} > c:\temp\output.txt
But the output bring me the following:
00000006|sleep
So it sees this as 1 string.
1- How can I get only those characters? (00000006)
2- How can I pass that to a variable which I then can use again for external execution?