Something like the following Powershell function should work for you:
function Get-Lines { [cmdletbinding()] param( [string]$filename, [string]$prefix ) if( Test-Path -Path $filename -PathType Leaf -ErrorAction SilentlyContinue ) { # filename exists, and is a file $lines = Get-Content $filename foreach ( $line in $lines ) { if ( $line -like "$prefix*" ) { $line } } } }
To use it, assuming you save it as get-lines.ps1, you would load the function into memory with:
. .\get-lines.ps1
and then to use it, you could search for all lines starting with "DATA" with something like:
get-lines -filename C:\Files\Datafile\testfile.dat -prefix "DATA"
If you need to save it to another file for viewing later, you could do something like:
get-lines -filename C:\Files\Datafile\testfile.dat -prefix "DATA" | out-file -FilePath results.txt
Or, if I were more awake, you could ignore the script above, use a simpler solution such as the following one-liner:
get-content -path C:\Files\Datafile\testfile.dat | select-string -Pattern "^DATA"
Which just uses the ^ regex character to make sure it's only looking for "DATA" at the beginning of each line.