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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:03:27+00:00 2026-05-28T04:03:27+00:00

I have a file frequencies.xml which contains lines with this form: <?xml version=1.0?> <!DOCTYPE

  • 0

I have a file “frequencies.xml” which contains lines with this form:

<?xml version="1.0"?>
<!DOCTYPE stationlist PUBLIC "-//xxxxx//DTD stationlist 1.0//EN"   "http://xxxxxxxxx/DTD/xxxxxxxx.dtd">
<frequencies xmlns="http://xxxxxxxxxxxxxxxx/DTD/">
 <list norm="PAL" frequencies="Custom" audio="bg">
..............................................................
<station name="A" active="1" channel="48.25MHz" norm="PAL"/>
<station name="B" active="1" channel="55.25MHz" norm="PAL"/>
<station name="C" active="1" channel="62.25MHz" norm="PAL"/>
<station name="D" active="1" channel="112.25MHz" norm="PAL"/>
..............................................................
<station name="E" active="1" channel="119.25MHz" norm="PAL"/>
<station name="F" active="0" channel="48.25MHz" norm="PAL"/>
..............................................................
<station name="G" active="1" channel="55.25MHz" norm="PAL"/>
<station name="H" active="0" channel="62.25MHz" norm="PAL"/>
..............................................................
  </list>
 </frequencies>

I want to remove line considered duplicate if contains same frequencies with other line.

Output results:

<station name="A" active="1" channel="48.25MHz" norm="PAL"/>
<station name="B" active="1" channel="55.25MHz" norm="PAL"/>
<station name="C" active="1" channel="62.25MHz" norm="PAL"/>
<station name="D" active="1" channel="112.25MHz" norm="PAL"/>
<station name="E" active="1" channel="119.25MHz" norm="PAL"/>

I write script to do this:

for i in `cat frequencies.xml | sed 's/.*channel="\([^"]*\)".*/\1/; /</ d' |grep MHz`; do
cat frequencies.xml | awk -v i="channel=\"$i" '
    BEGIN       { a=0 }
    $0 ~ i      { if ( a == "1" ) { print i"\" - duplicate" > "/dev/stderr"  ; next ;} ; a=1 } 
            { print $_ }' > frequencies.xml.tmp && \
mv frequencies.xml.tmp frequencies.xml
done

How transposing this in perl language?

Thanks

Update: I want to keep XML structure.

My code:

open (FH, "+< frequencies.xml") or die "Opening: $!";
my $out = '';
my %seen = ();
foreach my $line ( <FH> ) {
   if ( $line =~ m/<station/ ) {
        my ( $freq ) = ( $line =~ m/channel="([^"]+)"/ );
            $out .= $line unless $seen{$freq}++;
    } else {
        $out .= $line;
    }
}
seek(FH,0,0)                    or die "Seeking: $!";
print FH $out                   or die "Printing: $!";
truncate(FH, tell(FH))          or die "Truncating: $!";
close(FH)                       or die "Closing: $!";
  • 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-28T04:03:27+00:00Added an answer on May 28, 2026 at 4:03 am

    Keep a hash to track what frequencies you’ve seen, and if you’ve seen it, don’t emit the line:

    open INPUT, '<', 'frequencies.xml' or die "Can't read file : $!";
    my %seen = ();
    foreach my $line ( <INPUT> ) {
       my ( $freq ) = ( $line =~ m/channel="([^"]+)"/ );
       print $line unless $seen{$freq};
       $seen{$freq}++;
    }
    close INPUT;
    

    update :

    If there’s other lines to keep, you just need to print them. The easiest way is likely to just do the test if it’s a <station> element, and print everything else … but once you start getting more complex than this, you may want to use one of the true XML Parsers. So, using Zaid’s suggestion:

    open INPUT, '<', 'frequencies.xml' or die "Can't read file : $!";
    my %seen = ();
    foreach my $line ( <INPUT> ) {
       if ( $line =~ m/<station/ ) {
          my ( $freq ) = ( $line =~ m/channel="([^"]+)"/ );
          print $line unless $seen{$freq}++;
       } else {
          print $line;
       }
    }
    close INPUT;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have file called data_out.xml which contains this xml code: <?xml version=1.0 ?> -
I have file like this which contains 5 columns. But some rows in my
I have file Image_RGB565.raw which contains image buffer in RGB565 format. I want this
I have php file with form which the user need to enter three parameters
I have a file which is an XML representation of some data that is
I have file which looks like this: >gi|358482566|ref|NW_003766328.1| Gallus gallus breed Red Jungle fowl,
i have file which both show a form and validate it. when showing the
I have file sample.xml in my project set as content. I am running this
I have File Upload form which users use to upload certain files on the
Say I have file A, in middle of which have a tag string #INSERT_HERE#.

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.