Move line in text file

I am using

 (Get-Content .\*install.txt) | sort | get-unique | Set-Content installreport.txt 
to combine multiple log files into one and exclude duplicates. The log files all basically contain these types of strings:

OK
iTunes : OK
QuickTime : OK

Basically the first OK specifies that the updater application that ran, and the next lines show what applications were updated. On the final installreport.txt using get-unique removes the multiple top OK statements, but I would also like get the OK placed at the top of the text file (just the sing OK statement, not the ones next to the application names) . Currently it is sorted in the middle. Can someone point me into the right direction on how to do this?

Have you tried it just using the -Unique switch on the Sort-Object cmdlet instead of piping to the Get-Unique cmdlet?

Bob thanks for the tip. I tried with the sort -Unique, I get the same result as my command. I guess what I am trying to achieve is for the top item on the list to be OK and rest of the items can be in any order. In my example list it only shows one OK entry, but it is actually present for all lists. Without the -unique switch I get multiple entries. With the unique switch I just get one entry but it is in alphabetical order ( because that is what the sorting cmdlet is meant to do). I would like to have it be the first entry.

Without seeing more of your data and the alternatives to OK, it’s a little hard to guess because ‘O’ will never sort before ‘i’. Now if you had a field name associated with that first entry, it would be very easy (and natural) to build a hash table built on the name and sort accordingly.

Bob thanks for your answer:

Set-Content -Path .\installreport.txt -Value "OK" -Encoding Ascii
Get-Content -Path .\*Ninite.txt | where { $_ -notmatch "^OK$" } | select -Unique |
    Add-Content -Path .\installreport.txt
For some reason I was not able to reply to this thread for a little bit.  If I logged in, I would get a page not found for threads but they were available if I signed out.

You still need to provide an example of the actual data you are attempting to parse. What is in Ninite.txt and what results are you expecting to see with your script?

Bob helped me out with the code I pasted above on another forum. For some reason, this forum kept telling me that this was an invalid page when I was logged in. I could see the thread when I was not logged out though.

Ninite.txt is a log file for a installer. It basically spits out an OK if the exe was ran, and line by line what app it updated. I have several exes that leave these log files, and I wanted to combine them into one file. Just appending the log files made duplicates. Originally I wanted to keep the file similar to the original.

In the end I modified the code from Bob McCoy a little more and just threw out the OK lines since they really provided no value. I ended up using

 (Get-Content $tempPath*ninite.txt) | where { $_ -notmatch “^OK$” } | Sort-Object | Set-Content $Env:SystemDrive\ninitereport.txt -Force 

So is your script now doing what you need it to?

There is an issue that causes the seeming login issue. The trick to get it to work is to hit refresh on your browser. Drove me batty for a couple of days and Don told me about the refresh.

Bob,
Yes it is doing what I need it to do. Thanks.

Does one of the moderators resolve the thread or do I do it somehow?

You can do it by changing the thread status right above the reply box.

Under “Tread Status” I get two selections: General question, and Support question.

So you don’t get the option to resolve general questions (because there is nothing to resolve). If you change it to Support question, then you should get the option to mark it as resolved.