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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:39:42+00:00 2026-05-28T06:39:42+00:00

This ought to be ridiculously easy. I simply want to print a single element

  • 0

This ought to be ridiculously easy. I simply want to print a single element of an array. However, all I get from a command like print arr[1] is an empty line.

Here is my entire bash script:

#!/bin/bash
find -X $1 -type f | 
xargs md5 | 
awk '

NF == 4 {
     md5[$4]++;
     files[$2]++;
}

END {
    for (i = 1; i <= NF; i++)
    for (j = i + 1; j <= NF; j++)
        if (md5[i] == md5[j]) {
            print "These are duplicates: "
            print files[j+1]
            print files[i]
        }

'

exit 0

It is a very simply duplicate file finder. The problematic part is in the END{} statement within awk.

This just gives me a bunch of “These are duplicates: ” with empty lines after them. I know that the information is available, because I add this to END{}: for (x in arr); print x and it flawlessly prints every element in arr, as expected.

I must be doing something very silly.

  • 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-05-28T06:39:43+00:00Added an answer on May 28, 2026 at 6:39 am

    What you’re currently doing is assigning the values you want to save as the indices of the two arrays, which seems to be common from code examples in awk. However, that’s usually used in conjunction with the for (x in y) syntax. To fix your code, the way that comes to mind to fix what you’re doing is to modify your awk bit like so:

    BEGIN {
        md5idx = 0;
        filesidx = 0;
    }
    

    And then change:

    NF == 4 {
        md5[md5idx++] = $4;
        files[filesidx++] = $2;
    }
    

    That should about do it, I think, but I haven’t tested it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Another this ought to be easy but I don't know how to do it
This ought to simple. Say we have a struct from a library that doesn't
This questions seems like it already ought to be answered here, however I can't
This code below allows me to find the word error in all my files
I'm a little embarrassed to ask this as I ought to know better, but
This ought to be simple but I just can't figure this one out: The
I feel like this question ought to have been covered, but I can't seem
This seems like it ought to be simple, but I've tried both try {}
This string: [NSString stringWithFormat:@%C%C%C%C, 0x31, 0x34f, 0x32, 0x20dd] ought to display as 12 with
This ought to be pretty simple, maybe use a regex but I would think

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.