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

  • Home
  • SEARCH
  • 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 7936319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:10:39+00:00 2026-06-03T22:10:39+00:00

I have 2 files like these: file1 1 2 3 . . . 1

  • 0

I have 2 files like these:

file1

1 2 3 . . .

1 -2 4 . . .

1 2 5 . . .

. . . . . .

. . . . .

file 2

1 0.33 3 . . .

2 0.14 4 . . .

3 2.155 5 . . .

. . . . . .

. . . . . .

I need to check line by line the condition ($1==1 && $2==-2) in file1 and modify the corresponding line in file2, with $3=-2

I am trying with:

awk -F '\t' '{ BEGIN { FS=OFS="\t" } if ($1==1 && ($2==-2) {getline < "file2" ; $3=8; print $0} else {getline < "file2" ; print $0}  }' file1

So that the output file should be:

1 0.33 3 . . .

2 0.14 8 . . .

3 2.155 5 . . .

. . . . . .

. . . . . .

but it seems like some character or space is modified.
Maybe with Python it is simpler to tackle this problem?
Any suggestion?

  • 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-03T22:10:41+00:00Added an answer on June 3, 2026 at 10:10 pm

    Since you asked about python

    #!/usr/bin/env python
    
    with open('f1') as  fd:
        f1 = [map(int,i.strip().split()) for i in fd]
    with open('f2') as  fd:
        f2 = [map(float,i.strip().split()) for i in fd]
    
    for n, f in enumerate(f2):
        if f1[n][0] == 1 and f1[n][1] == -2:
            print f[0], f[1], 8
        else:
            print f
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have few links to .mp4 video files like file1.mp4 file2.mp4 file3.mp4 I need
I want to parse xml files that have elements like these: <element>&amp</element> <element>&amp;</element> But
I have a question about unix command line. I have many files like these:
I have a few log files like these: /var/log/pureftpd.log /var/log/pureftpd.log-20100328 /var/log/pureftpd.log-20100322 Is it possible
I have files served like so: AJAX request handler -> Include file I would
I have a list of text files file1.txt, file2.txt, file3.txt .. filen.txt that I
E.g., I have the following files under version control: file1, file2, file3, all at
I have several hundred files in a folder. Each of these file is a
I have a text file that looks like this: value1 value2 value3 There are
We have multiple log files like database log, weblog, quartzlog in our application. Any

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.