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.
This code uses
headto get the first line,tailto get the rest,cutto get only the starting columns,pasteto add additional columns, (these two assume tab is used to separate columns),yesto generate the columns.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: