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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:00:41+00:00 2026-06-09T02:00:41+00:00

I asked previously how to correct errors in count data using awk, where the

  • 0

I asked previously how to correct errors in count data using awk, where the first column of my data is a number used to identify the sub-arena that’s being measured, and the second column is the count data from that sub-arena. The counting is automated and the program makes errors (indicated below with #), where it will occasionally ‘miscount’ because the animals that are being counted have moved outside the range of the specific sub-arena.

1       0
1       2
1       6
1       7
1       7
1       8
1       7 #
1       7 #
1       9
2       0
2       0
2       1
2       4
2       3 #
2       3 #
2       4
2       4
2       6

I’d like to correct the above like so:

1       0
1       2
1       6
1       7
1       7
1       8
1       8
1       8
1       9
2       0
2       0
2       1
2       4
2       4
2       4
2       4
2       4
2       6

The code that was kindly suggested didn’t include a for loop for correcting within the data for each arena (there are 20 total per file) and I’ve been trying to figure this out but am having an incredibly hard time, with syntax errors some times and illegal statement errors other times. I’d appreciate any hints as to why the following won’t work (sorry I’m such a newbie, this is one of the many iterations that I’ve tried and none of them are pretty):

awk 'i=1; i<=20; i++; $1=i {NR > 1 && $2 < p {$2 = p} {p = $2} 1}' infile > outfile
  • 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-09T02:00:42+00:00Added an answer on June 9, 2026 at 2:00 am

    Rather than counting the lines, why not have another variable tracking the line number which resets p if the line number increments:

    awk '$1 > l { l = $1; p = 0 } $2 < p { $2 = p } { p = $2 } 1' input-file
    

    First the first position ($1) is compared to the value in the l variable (that defaults to 0). If it’s greater, l is set to $1, and p is reset to 0. Then the second position ($2) is compared to p, and if it’s less set to p. Finally, p is set to the value of the (possibly changed) $2. The final 1 just means “print”; otherwise the command would do all the processing but not print any of it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had previously asked about Converting using SqlConnection to Func delegate How can I
I previously asked this question about how to make versioned serializaion using boost::serialization::access I
I previously asked this question here: Stop user from using enter to pass a
What is the difference between parseInt(string) and Number(string) in JavaScript has been asked previously.
This is something I've asked previously , with a suggested solution of using mod_proxy,
I know this question was asked previously and the reply was to override onPrepareContextMenu()/onCreateContextMenu().
difficult to look this up if it has been asked previously since I don't
This is related to a question I've asked previously: Calling Javascript function after loading
OK, I know that this has been asked previously, so please forgive me for
I previously asked a question about fetching the last 100 mentions for a person

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.