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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:30:11+00:00 2026-06-05T18:30:11+00:00

I am working in linux bash environment, and I have many files to edit,

  • 0

I am working in linux bash environment, and I have many files to edit, 900 or so.
In one file,filename.txt, I have list of file names, one file name per line.
for example

ab2.pdb.101
ab2.pdb.109
ab2.pdb.126
ab2.pdb.127
ab2.pdb.13
ab2.pdb.187
ab2.pdb.188

and the first few lines of context of these files are like,(total of 245 lines)

REMARK   1                     PDB file generated by ptraj (set    33)
ATOM      1  N   ALA     1      11.304   3.018  20.878  0.1414  1.8240
ATOM      2  H1  ALA     1      11.574   3.686  21.593  0.1997  0.6000
ATOM      3  H2  ALA     1      11.901   3.162  20.074  0.1997  0.6000
ATOM      4  H3  ALA     1      10.342   3.207  20.625  0.1997  0.6000
ATOM      5  CA  ALA     1      11.449   1.637  21.381  0.0962  1.9080
ATOM      6  HA  ALA     1      12.509   1.464  21.561  0.0889  1.1000

I would like to replace the last two columns of numers from second line to the end of file with 0.0000 0.0000

0.1414  1.8240
0.1997  0.6000
0.1997  0.6000
0.1997  0.6000
0.0962  1.9080
0.0889  1.1000

to

0.0000  0.0000
0.0000  0.0000
0.0000  0.0000
0.0000  0.0000
0.0000  0.0000
0.0000  0.0000

So I would like to read in a file which file names are in one text file named “filenames.txt” and replace last two column numbers to 0.0000.

Thank you all for any 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-06-05T18:30:13+00:00Added an answer on June 5, 2026 at 6:30 pm

    This code uses head to get the first line, tail to get the rest, cut to get only the starting columns, paste to add additional columns, (these two assume tab is used to separate columns), yes to generate the columns.

    #! /bin/bash
    while read file ; do {
            head -n1 "$file"
            tail -n+2 "$file" | \
                cut -f1-8 | \
                paste - <( yes 0.0000$'\t'0.0000 | \
                head -n $(( $( wc -l < "$file")-1 ))
            )
        }  > "$file".new
    done < filenames.txt
    

    Update:
    If the structure of the files is more complicated, I would use something more comfortable than bash. For example, this is how to do it in Perl:

    #!/usr/bin/perl
    use warnings;
    use strict;
    
    open my $NAMES, '<', 'filenames.txt' or die $!;
    for my $file (<$NAMES>) {
        chomp $file;
        open my $FILE, '<', $file or die $!;
        open my $NEW,  '>', "$file.new" or die $!;
        print {$NEW} scalar <$FILE>;               # print 1st line
        while (<$FILE>) {
            my @fields = split /(\s+)/;            # keep separators
            @fields[-4, -2] = ('0.0000') x 2;      # replace the last two non-whitespace columns
            print {$NEW} @fields;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Actually I have a file . I am working in linux environment. I need
Working in bash under Linux ubuntu 10 here I have Bash script that reads
Working under linux for our developement, I have an Eclipse Makefile C Project and
Iam working on Ubuntu.(Linux) I want to redirect from the page one.php to two.php,
I have a bash file, which I’m trying to run in Cygwin on a
My same BASH script is working in Fedora/CentOS. But I am testing one Android
I am new to linux & bash, and I am working on some different
I'm working on Linux gcc environment and I need to initilize function arguments that
I currently working with embedded linux with bash shell on it. Write now I
I have a C file running on Linux. It prints some lines in red

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.