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 148749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:00:51+00:00 2026-05-11T09:00:51+00:00

I have a comma delimited file myfile.csv where the 5th column is a date/time

  • 0

I have a comma delimited file ‘myfile.csv’ where the 5th column is a date/time stamp. (mm/dd/yyyy hh:mm). I need to list all the rows that contain duplicate dates (there are lots)

I’m using a bash shell via cygwin for WinXP

$ cut -d, -f 5 myfile.csv | sort | uniq -d  

correctly returns a list of the duplicate dates

01/01/2005 00:22 01/01/2005 00:37 [snip]     02/29/2009 23:54 

But I cannot figure out how to feed this to grep to give me all the rows. Obviously, I can’t use xargs straight up since the output contains spaces. I thought I could do uniq -z -d but for some reason, combining those flags causes uniq to (apparently) return nothing.

So, given that

 $ cut -d, -f 5 myfile.csv | sort | uniq -d -z | xargs -0 -I {} grep '{}' myfile.csv 

doesn’t work… what can I do?

I know that I could do this in perl or another scripting language… but my stubborn nature insists that I should be able to do it in bash using standard commandline tools like sort, uniq, find, grep, cut, etc.

Teach me, oh bash gurus. How can I get the list of rows I need using typical cli tools?

  • 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. 2026-05-11T09:00:51+00:00Added an answer on May 11, 2026 at 9:00 am
    1. sort -k5,5 will do the sort on fields and avoid the cut;
    2. uniq -f 4 will ignore the first 4 fields for the uniq;
    3. Plus a -D on the uniq will get you all of the repeated lines (vs -d, which gets you just one);
    4. but uniq will expect tab-delimited instead of csv, so tr ‘\t’ ‘,’ to fix that.

    Problem is if you have fields after #5 that are different. Are your dates all the same length? You might be able to add a -w 16 (to include time), or -w 10 (for just dates), to the uniq.

    So:

    tr '\t' ',' < myfile.csv | sort -k5,5 | uniq -f 4 -D -w 16 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file, delimited by comma and I have some date values
I have a comma delimited list of record id's: string = 2207,117,90,2168,120,118,113,112,17 I need
I have a csv file that is comma delimited. I have no problem with
I have a huge file that I need to filter out all lines (comma
Possible Duplicate: Reading csv file I have a comma delimited file: Some Text, More
I have a comma delimited CSV file being loaded into a String value generated
I have a comma delimited text file. The 5th field on each line contains
I am using C#, I have a comma delimited csv file with different strings
I have a comma delimited list of ids that I want to use to
I am not good at SQL Server 2000. I have a comma-delimited list of

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.