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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:48:43+00:00 2026-05-31T10:48:43+00:00

I am trying to find everywhere my data has a 90 in column 2

  • 0

I am trying to find everywhere my data has a 90 in column 2 and two lines above change the value of column 2. For example in my data below, if I see 90 at line 11 I want to change my column 2 value at line 9 from 11 to 5. I have a predetermined set of values I want to change the number to; the values will always be 10,11,12,30,31,32 to 1,2,3,4,5,6 respectably.

My data

 #      Type    Response        Acc     RT      Offset    
   1      70  0    0   0.0000 57850
   2      31  0    0   0.0000 59371
   3      41  0    0   0.0000 60909
   4      70  0    0   0.0000 61478
   5      31  0    0   0.0000 62999 
   6      41  0    0   0.0000 64537
   8      70  0    0   0.0000 65106
   9      11  0    0   0.0000 66627
  10      21  0    0   0.0000 68165
  11      90  0    0   0.0000 68700
  12      31  0    0   0.0000 70221

What I want

 #      Type    Response        Acc     RT      Offset    
   1      70  0    0   0.0000 57850
   2      31  0    0   0.0000 59371
   3      41  0    0   0.0000 60909
   4      70  0    0   0.0000 61478
   5      31  0    0   0.0000 62999 
   6      41  0    0   0.0000 64537
   8      70  0    0   0.0000 65106
   9       5  0    0   0.0000 66627
  10      21  0    0   0.0000 68165
  11      90  0    0   0.0000 68700
  12      31  0    0   0.0000 70221

I have been trying to store the previous line and use that as a reference but I can only go back one line, and I need to go back two. Thank you for your help.

  • 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-31T10:48:45+00:00Added an answer on May 31, 2026 at 10:48 am

    This should work:

    function pra(a) {
      for(e in a) {
        printf "%s ", a[e];
      }
      print ""; 
    }
    BEGIN {
      vals[10] = 1;
      vals[11] = 2;
      vals[12] = 3;
      vals[30] = 4;
      vals[31] = 5;
      vals[32] = 6;
    }
    NR == 1 { split($0, a, " ") }
    NR == 2 { split($0, b, " ") }
    NR > 2 { 
      if($2 == "90") {
        a[2] = vals[a[2]];
      }
      pra(a);
      al = 0;
      for(i in a) al++;
      for(i = 1; i <= al; i++) {
        a[i] = b[i];
      }
      split($0, b, " ");
    }
    END {
      pra(a);
      pra(b);
    }
    

    The rundown of how this works:
    * BEGING block – assign the translation values to vals
    * NR == 1 and NR == 2 – remember the first two lines into split arrays a and b
    * NR > 2 – for all lines after the first two
    * If the second column has value 90, change it using the translation array
    * Move elements of array b to a and split the current line into b
    * END block – print a and b, which are basically last two lines

    Sample run:

    $ cat inp && awk -f mkt.awk inp 
     #      Type    Response        Acc     RT      Offset    
       1      70  0    0   0.0000 57850
       2      31  0    0   0.0000 59371
       3      41  0    0   0.0000 60909
       4      70  0    0   0.0000 61478
       5      31  0    0   0.0000 62999 
       6      41  0    0   0.0000 64537
       8      70  0    0   0.0000 65106
       9      11  0    0   0.0000 66627
      10      21  0    0   0.0000 68165
      11      90  0    0   0.0000 68700
      12      31  0    0   0.0000 70221
    
    # Type Response Acc RT Offset 
    1 70 0 0 0.0000 57850 
    2 31 0 0 0.0000 59371 
    3 41 0 0 0.0000 60909 
    4 70 0 0 0.0000 61478 
    5 31 0 0 0.0000 62999 
    6 41 0 0 0.0000 64537 
    8 70 0 0 0.0000 65106 
    9 2 0 0 0.0000 66627 
    10 21 0 0 0.0000 68165 
    11 90 0 0 0.0000 68700 
    12 31 0 0 0.0000 70221 
    

    You can do something like this:

    function pra(a) {
      printf "%4d%8d%3d%5d%9.4f%6d\n", a[1], a[2], a[3], a[4], a[5], a[6]
    }
    BEGIN {
      vals[10] = 1;
      vals[11] = 2;
      vals[12] = 3;
      vals[30] = 4;
      vals[31] = 5;
      vals[32] = 6;
    }
    NR == 1 { print }
    NR == 2 { split($0, a, " ") }
    NR == 3 { split($0, b, " ") }
    NR > 4 {
      if($2 == "90") {
        a[2] = vals[a[2]];
      }
      pra(a);
      for(i = 1; i <= 6; i++) {
        a[i] = b[i];
      }
      split($0, b, " ");
    }
    END {
      pra(a);
      pra(b);
    }
    

    To make it work for this specific case that includes formatting. Sample run:

    $ cat inp && awk -f mkt.awk inp 
     #      Type    Response        Acc     RT      Offset    
       1      70  0    0   0.0000 57850
       2      31  0    0   0.0000 59371
       3      41  0    0   0.0000 60909
       4      70  0    0   0.0000 61478
       5      31  0    0   0.0000 62999 
       6      41  0    0   0.0000 64537
       8      70  0    0   0.0000 65106
       9      11  0    0   0.0000 66627
      10      21  0    0   0.0000 68165
      11      90  0    0   0.0000 68700
      12      31  0    0   0.0000 70221 
     #      Type    Response        Acc     RT      Offset    
       1      70  0    0   0.0000 57850
       2      31  0    0   0.0000 59371
       4      70  0    0   0.0000 61478
       5      31  0    0   0.0000 62999
       6      41  0    0   0.0000 64537
       8      70  0    0   0.0000 65106
       9       2  0    0   0.0000 66627
      10      21  0    0   0.0000 68165
      11      90  0    0   0.0000 68700
      12      31  0    0   0.0000 70221
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to find an example that has css rollover using sprites & sliding door
I'm been hunting everywhere trying to find how to access data returned via a
Im trying to find records in a VARCHAR column that may contain a NUL
I trying to find function in PHP that can output the binary data. The
I have looked almost everywhere trying to find a way to save my android
I have been trying to find a solution to this everywhere but am stumped.
I searched everywhere but could not find a solution to this. I am trying
Trying to find the best way of create an overlap/overlay layer to fill the
Trying to find a good name for a method swapping each coordinate X and
Trying to find a way to send a POST HTTPS request from Python to

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.