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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:49:36+00:00 2026-06-18T05:49:36+00:00

In Linux, I have a program that changes a list of coordinates slightly as

  • 0

In Linux, I have a program that changes a list of coordinates slightly as it runs through some number of iterations. I can use grep -c to count the number of iterations and I want to grab the last set of labels and coordinates from that programs output.

My source file looks something like:

text
total number of objects with coordinates = n
text
begin coordinates
label1 x1 y1 z1
label2 x2 y2 z2
...
labeln xn yn zn
end coordinates
text
text
begin coordinates
label1 a1 b1 c1
label2 a2 b2 c2
...
labeln an bn cn
end coordinates
text
text

In this case I would want to dump the set of labels along with their a, b and c coordinates to a text file that would look like this:

label1 a1 b1 c1
label2 a2 b2 c2
...
labeln an bn cn

My preference would be to use something like grep or awk to do this, but I’m not familiar enough with them to implement this.

EDIT: I forgot to mention that the labels are neither constant nor unique so label2 could equal label5 or labeln.

  • 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-18T05:49:38+00:00Added an answer on June 18, 2026 at 5:49 am

    Whenever you see begin coordinates, start saving a new block of text. Stop saving it when you see end coordinates. At the end of the file, print the last block of text that you saved.

    #!/usr/bin/env awk -f
    
    /^begin coordinates/ { text = ""; save = 1 }
    save { text = text $0 "\n" }
    /^end coordinates/ { save = 0 }
    END { print text }
    

    Note that text = text $0 "\n" is concatenating the variables text and $0 with \n. Whitespace is awk’s concatenation operator.

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

Sidebar

Related Questions

So I have a Linux program that runs in a while(true) loop, which waits
I have a C++ program on Linux that crashes after some time with the
I have a linux C program that handles request sent to a TCP socket
I have a python program that must work on Windows and Linux. There are
I'm looking for some command-line tools for Linux that can help me detect and
I have a C program that runs a scientific simulation and displays a visualisation
I am working on this old c++ program that runs in Linux. It is
I have a program that accesses a device through the serial port and reads
If I have a multi-threaded program that reads a cache-type memory by reference. Can
I have a program that I am writing and that needs to calculate some

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.