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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:09:22+00:00 2026-06-08T06:09:22+00:00

Here’s what I’m trying to achieve: File 1 has contents something like this: .

  • 0

Here’s what I’m trying to achieve:

File 1 has contents something like this:

.

.

.

get_time file 10 -max 5 -min 0 abcde

get_time file 9 -max 5 -min 0 abfdf

get_time file 9 -max 5 -avg 3 -min 0 xyyxx

get_time file 10 -max 5 -min 0 abcxx

.

.

.

Meanwhile file 2 just contains:

abcde 8

abfdf 8.5

xyyxx 7.5

abcxx 9

.

.

.

What I need is a file 3 that prints out exactly whats there in file 1, except replace the value in column 3 correspondingly.

So the output should look like:

.

.

.

get_time file 8 -max 5 -min 0 abcde

get_time file 8.5 -max 5 -min 0 abfdf

get_time file 7.5 -max 5 -avg 3 -min 0 xyyxx

get_time file 9 -max 5 -min 0 abcxx

.

.

.

Note: File 1 contains a lot of other stuff that don’t start with “get_time” before and after it. They’re noted as dots in the example above.

Thanks for your help!

Edit: Thanks! Quick follow-up. Another similar file has something like this instead:

get_time file123 tmp 10 -max 5 -min 0 abcde 

get_time file foo 9 -max 5 -min 0 abfdf 

get_time file43 bar 9 -max 5 -avg 3 -min 0 xyyxx 

How would you modify your script? Thanks again

  • 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-08T06:09:24+00:00Added an answer on June 8, 2026 at 6:09 am

    Read file 2 into a hash or dictionary, where the key is the 5-letter tag.

    Read file 1 one line at a time, replacing the value in the third column with the value found in the hash or dictionary based on the tag that appears at the end of the line.


    Perl

    #!/usr/bin/env perl
    use strict;
    use warnings;
    use English qw( -no_match_vars );
    
    my %times;
    
    $OFS = " ";
    
    open my $file, "<", "file2" or die "Failed to open file2 ($!)";
    while (<$file>)
    {
        my($key,$value) = split;
        $times{$key} = $value;
    }
    close $file;
    
    while (<>)
    {
        if (/^get_time file/)
        {
            my(@words) = split;
            my($keycol) = $words[$#words];
            $words[2] = $times{$keycol} if defined $times{$keycol};
            print @words, "\n";
            next;
        }
        print;
    }
    

    I make no claims that it is superlative Perl; it does seem to work given:

    file1

    .X1X.
    .X2X.
    .X3X.
    get_time file 10 -max 5 -min 0 abcde
    get_time file 9 -max 5 -min 0 abfdf
    get_time file 9 -max 5 -avg 3 -min 0 xyyxx
    get_time file 10 -max 5 -min 0 abcxx
    .X4X.
    .X5X.
    .X6X.
    

    file2

    abcde 8
    abfdf 8.5
    xyyxx 7.5
    abcxx 9
    

    output

    .X1X.
    .X2X.
    .X3X.
    get_time file 8 -max 5 -min 0 abcde 
    get_time file 8.5 -max 5 -min 0 abfdf 
    get_time file 7.5 -max 5 -avg 3 -min 0 xyyxx 
    get_time file 9 -max 5 -min 0 abcxx 
    .X4X.
    .X5X.
    .X6X.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is what I am trying to achieve in PHP: I have this string:
Here is the code in a function I'm trying to revise. This example works
Here's my code in the <head></head> : <link rel=stylesheet href=http://code.jquery.com/mobile/1.1.0/jquery.mobile-1.1.0.min.css /> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js></script>
Basically, what I'm trying to create is a page of div tags, each has
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()
Here is what I want to do. Use this HTML line and have the
Here's my .htaccess file: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule .*
Here is my text file forms. S1,F2 title including several white spaces (abbr) single,Here<->There,reply
Here are some facts about my app followed by a question My app has
Here are the tables I have: Table A which has entries with item and

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.