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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:29:14+00:00 2026-05-25T01:29:14+00:00

I have files with the format: ATOM 3736 CB THR A 486 -6.552 153.891

  • 0

I have files with the format:

ATOM   3736  CB  THR A 486      -6.552 153.891  -7.922  1.00115.15           C  
ATOM   3737  OG1 THR A 486      -6.756 154.842  -6.866  1.00114.94           O  
ATOM   3738  CG2 THR A 486      -7.867 153.727  -8.636  1.00115.11           C  
ATOM   3739  OXT THR A 486      -4.978 151.257  -9.140  1.00115.13           O  
HETATM10351  C1  NAG B 203      33.671  87.279  39.456  0.50 90.22           C  
HETATM10483  C1  NAG Z 702      28.025 104.269 -27.569  0.50 92.75           C    
ATOM   3736  CB  THR X 486      -6.552  86.240   7.922  1.00115.15           C  
ATOM   3737  OG1 THR X 486      -6.756  85.289   6.866  1.00114.94           O  
ATOM   3738  CG2 THR X 486      -7.867  86.404   8.636  1.00115.11           C  
ATOM   3739  OXT THR X 486      -4.978  88.874   9.140  1.00115.13           O  
HETATM10351  C1  NAG Y 203      33.671 152.852 -39.456  0.50 90.22           C  
HETATM10639  C2  FUC C 402     -48.168 162.221 -22.404  0.50103.03           C  

For each block of lines starting with HETATM*, I would like to change column 5 to match that of the previous ATOM block. It means that for the first HETATM* block both B and Z will change to A, whereas for the second HETATM* block both Y and C will change to X.

A second question, I do not really need to do it, it is just out of curiosity, how would I split the file after each line starting with HETATM* but only if the next line is ATOM?

  • 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-25T01:29:14+00:00Added an answer on May 25, 2026 at 1:29 am

    Here is my solution, which solves the first problem (replacing the fifth field) while preserving white spaces:

    $1=="ATOM" {
        fifthField=$5
    
        # Block to determine which index position field #5 is
        fifthField_index = 1
        for (i = 0; i < 4; i++) {
            // Skip until white space
            for (; substr($0, fifthField_index, 1) != " "; fifthField_index++) { }
            // Skip white spaces
            for (; substr($0, fifthField_index, 1) == " "; fifthField_index++) { }
        }
    
        print;next
    }
    
    /^HETATM/ {
        before_fifthField = substr($0, 1, fifthField_index - 1)
        after_fifthField = substr($0, fifthField_index + 1, length($0))
        print before_fifthField fifthField after_fifthField
        next
    }
    
    1
    

    It is not the most elegant solution, but it works. This solution assumes that the fifth field is a single character.

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

Sidebar

Related Questions

I have files with the following format: ATOM 3736 CB THR A 486 -6.552
I have text files containing structured data (it is a proprietary format and not
I would like to rename files numbering: I have a files with '???' format
I have a directory with timestamped files in the format: processAlpha20120618.txt processAlpha20120619.txt processAlpha20120620.txt processBeta20120618.txt
Is there any tool that can parse/conver xml files to this format? I have
I have a bunch of files that were named in a somewhat standard format.
Is the endianness of format params guaranteed in RIFF WAV files? I have heard
I'm writing a simple batch downloader for files, which have the format Y-m-d.pdf. I
I have a XML File in the following format: <?xml version='1.0' encoding='UTF-8'?> <entry xmlns='http://www.w3.org/2005/Atom'
I have files in S3 bucket, and their names have the following format: username#file_id#...

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.