• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Filtering and displaying specific lines from a log file in PowerShell

Resolved: Filtering and displaying specific lines from a log file in PowerShell

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

I have a system generated log file, which includes values such as approvals and rejections transactions line by line on daily basis every 30 minutes, we require to extract and print the line of rejected transaction, currently this log file goes above 200 to 300 lines and we have to manually check the logs. Is there a way in PowerShell where I can just print the rejected values in the file eg:
logfile (actual)
[08:03:33] 1209031,,,,,status,trnasaction, requested
[08:04:33] 1548215,,,,,status,trnasaction, response
[08:06:33] 1852415,,,,,status,trnasaction, Rejected
[08:09:33] 1685941,,,,,status,trnasaction, approved
[08:11:33] 1548215,,,,,status,trnasaction, response
[08:15:33] 1852415,,,,,status,A73IF4DE5,heartbeat, Rejected
[08:21:33] 1685941,,,,,status,,transaction, Rejected

logfile (output)
[08:06:33] 1852415,,,,,status,trnasaction, Rejected
[08:15:33] 1852415,,,,,status,A73IF4DE5,heartbeat, Rejected
[08:21:33] 1685941,,,,,status,,transaction, Rejected

Answer:

You can import the log in a variable with Get-Content and then you can filter with Select-String, below a little example:

If you have better answer, please add a comment about this, thank you!

criteria filter logfile powershell
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: TYPO3 SQL error: Field ‘tx_imagezoom_set’ doesn’t have a default value

26/03/2023

Resolved: std::regex_replace to replace multiple combinations

26/03/2023

Resolved: How can I copy files using the ansible.builtin.copy module and avoid conflicting file names?

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.