Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:48:51+00:00 2026-06-13T20:48:51+00:00

I have a pipe delimited flat file from which I need to deduplicate the

  • 0

I have a pipe delimited flat file from which I need to deduplicate the entries based on an object, to be specific a part of file is:

"001A"|"1"|"*"||"A"|"504367667"|"1"|"2005-06-10-16.57.23.000000"|
"001A"|"1"|"*"||"A"|"504367667"|"1"|"2005-10-24-16.52.29.000000"|
"001A"|"1"|"*"||"A"|"504367667"|"1"|"2007-12-13-15.48.47.000000"|
"001A"|"1"|"*"||"A"|"504367667"|"1"|"2008-12-09-17.10.39.000000"|
"001B"|"1"|"*"||"B"|"800026800"|"1"|"2005-08-08-10.48.16.000000"|
"001C"|"1"|"*"||"C"|"490349139"|"1"|"2006-01-19-12.03.08.000000"|
"001C"|"1"|"*"||"C"|"490349139"|"1"|"2009-03-12-15.08.11.000000"|

The first field is ID and last field is a timestamp, I want to deduplicate the entries such that only the latest timestamp entry is kept for each ID. So, The output that I need should be:

"001A"|"1"|"*"||"A"|"504367667"|"1"|"2008-12-09-17.10.39.000000"|
"001B"|"1"|"*"||"B"|"800026800"|"1"|"2005-08-08-10.48.16.000000"|
"001C"|"1"|"*"||"C"|"490349139"|"1"|"2009-03-12-15.08.11.000000"|

I read the file and stored the entries in an array with distinct object names, then I tried

$inputdeduped = $inputfilearray | Sort-Object Date
$inputdeduped = $inputdeduped | Select-Object ID -Unique

hoping that once the date is sorted, get-unique cmdlet used as -unique here would either pick either the first or last of the duplicated entry in the sorted array so depending on that I would sort the date in either desc or asc order, however it doesn’t and randomly picks one entry.

Please help me out guys or help me understand how the get-unique cmdlet works.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:48:53+00:00Added an answer on June 13, 2026 at 8:48 pm

    you can try this:

      $newInputdeduped =  $inputfilearray | sort id, date -ascending | group -Property id |
         select @{n="GroupedList"; e={ $_.group | select -first 1 }} |
         select -expa list 
    

    This is what I do with your example data after saving it as a txt file:

    > $a = Import-Csv -Header "id","n1","n2","v1","n3","n4","n5","date"  -Path .\c.txt -delimiter '|'
    
    > $a | ft -AutoSize
    
    id   n1 n2 v1 n3 n4        n5 date
    --   -- -- -- -- --        -- ----
    001A 1  *     A  504367667 1  2005-06-10-16.57.23.000000
    001A 1  *     A  504367667 1  2005-10-24-16.52.29.000000
    001A 1  *     A  504367667 1  2007-12-13-15.48.47.000000
    001A 1  *     A  504367667 1  2008-12-09-17.10.39.000000
    001B 1  *     B  800026800 1  2005-08-08-10.48.16.000000
    001C 1  *     C  490349139 1  2006-01-19-12.03.08.000000
    001C 1  *     C  490349139 1  2009-03-12-15.08.11.000000
    
    > $b = $a | sort id, date -ascending | group -Property id | select @{n="list";e={ $_.group | select -first 1  }} | select -expa list
    
        > $b | ft -AutoSize
    
    id   n1 n2 v1 n3 n4        n5 date
    --   -- -- -- -- --        -- ----
    001C 1  *     C  490349139 1  2009-03-12-15.08.11.000000
    001B 1  *     B  800026800 1  2005-08-08-10.48.16.000000
    001A 1  *     A  504367667 1  2008-12-09-17.10.39.000000
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pipe delimited text file as shown below, which I need to
I have a flat file that is pipe delimited and an database table. I
I have a pipe delimited feed file which has several fields. Since I only
I have the need to parse through a large pipe-delimited file to count the
I have a flat file that is pipe delimited and looks something like this
hi guys i have two pipe delimited files,first file contains 1000 records and second
I have a pipe to gnuplot which I use to graph a file. The
I have the following file (above) which seems to be an Unix pipe alt
I have a flat array of pipe-delimited strings: Array ( [0] => style1|000000 [1]
I have a pipe delimited file with some NULL date fields. I load this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.