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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:52:16+00:00 2026-06-16T00:52:16+00:00

I have an XML-File with <pb n=4-DIGIT-NUMBER … /> . The number being in

  • 0

I have an XML-File with <pb n="4-DIGIT-NUMBER" ... />. The number being in some cases identical, so I’d like to disambiguate, coming so far, but now problems with counting (do I have the right approach? => 3))

1) Reading the all numbers into an Array, yielding a very long list with:

Dir.chdir("./Tustep/luxneu")
sammel = []
open("lp42tags.txt").each do |x|
  if x =~ /<pb n="(\d\d\d\d)/
  sammel << $1
  end
end

2) Finding the numbers repeating and put them into subarrays

dupl_groups = sammel.select{|i| sammel.grep(i).size > 1}.group_by{|x| x}.values
p dupl_groups
# (much shorter example)=> [["0119", "0119"], ["0147", "0147"], ["0156", "0156", "0156"]]

3) Now I thought I could somehow count the elements of each subarray and put them back into (or into a copy..). I want e.g. [[“0119:1”, “0119:2”], […], [“0156:1”, “0156:2”, “0156:3”], maybe like this (but only got hilarious loops with almost endless number computations… :/)

dupl_counted = []
dupl_groups.each do |outer|
  count = 1
  dupl_groups do |inner|
    #puts inner.inspect
    inner_new = inner.to_s.sub(/(.+)/, "\\1:#{count}")
    dupl_counted << inner_new
    count += count
  end
end

Seriously flawed..? Maybe something instead using “each_with_index”? Also I need the groups for counting in meaningful chunks (slice 3 or so is unacceptable, because there are number-repetitions ranging from 2-6). If I could split the array in its subarrays yielding them all as normal arrays, would that be good?

Thanks in advance!
René T.

  • 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-16T00:52:17+00:00Added an answer on June 16, 2026 at 12:52 am

    This should be just a nested application of map – once to the outer group, and then to each element within:

    dupl_groups.map do |gp| 
      gp.map.with_index {|el, ix| el + ":#{ix+1}"}
    end
    # => [["0119:1", "0119:2"], ["0147:1", "0147:2"], ["0156:1", "0156:2", "0156:3"]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have XML file (output of some application) like this: <data> <call function=get_user_data> <output>
I have xml file that defines some preference screens like the following example <PreferenceScreen
I have an XML file from which I am parsing some content to display
I have an XML file that looks like <?xml version=1.0> <playlist> <name>My Playlist</name> <song>
I have an XML file that reads like this <abc> <ab>value</ab> <aa>time</aa> <ac>money</ac> </abc>
I have xml file like this: <lala> <blabla> <qweqwe>test</qweqwe> </blabla> </lala> I need to
We have XML file like below... <?xml version='1.0'?> <T0020 xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation=http://www.safersys.org/namespaces/T0020V1 T0020V1.xsd xmlns=http://www.safersys.org/namespaces/T0020V1> <IRP_ACCOUNT>
I have xml file like this <?xml version=1.0 encoding=UTF-8?> <specification xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=file://Desktop/normal.xsd> <university> <refstr>bdvl_te_skrm_stc</refstr>
have a XML file like this: <Datasets> <package id=AD> <iff>LRC_AD_AMSADTEXPDR</iff> </package> <package id=AL> <iff>LRC_AL_CLINICALTCODE</iff>
i want parse xml file, which does't have xml extension, like this: http://bizonek.wrzuta.pl/xml/plik/1ANdXCgTOit/unknow/undefined/643/ my

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.