Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
where I used a blank character to shift the fifth field one character to the right.
By the way, your sed command doesn't work mainly because you are using single quotes
which don't allow $i to be expanded to the value of shell variable $i. Try with double quotes.
#!/bin/bash
# Script to alter position of residue number in pdb file for resid above 999
i=$(awk '{print $5}' wt-test.pdb | uniq)
for i in $i;
do
if [ "$i" -gt "999" ]; then
sed 's/ $i / $i/g' wt-test.pdb > wt-test-out.pdb ;
fi
done
Do you just want the "$i" to be substituted for the variable's value in the argument for sed? If so, use this:
Code:
#!/bin/bash
# Script to alter position of residue number in pdb file for resid above 999
i=$(awk '{print $5}' wt-test.pdb | uniq)
for i in $i;
do
if [ "$i" -gt "999" ]; then
sed 's/ '"$i"' / '"$i"'/g' wt-test.pdb > wt-test-out.pdb ;
fi
done
perl script to alter character positions in pdb file
Dear all,
Many thanks for all your replies.
I tried awk but after substitution, the specific character spacing between columns is no longer preserved. You can specify your output to be comma or tab or space separated etc but you cannot retain specific character spacing between different columns. I believe that is a drawback of awk.
As for sed, although it can retain column spacing after substitution, but if I place it in a loop over all the variables I want replaced, it performs substitution multiple times on the same original file, resulting in only the last value of the variable being substituted in the output. One way around is to keep creating temporary files for each substitution, with the next substitution working on the previous output temporary file.
I have a perl script that can help users adjust pdb column spacings. The script works by splitting each column in the original file on spaces, then reassigning columns to have specific character widths, and values in the column to be left or right aligned. Please take a look at the standard pdb format (from PDB website) before modifying the script. The script must be modified to work on different pdb files, especially if chain numbers are present or absent etc. The script can also renumber atom numbers. I hope it will be useful as a starting point for people who need to modify pdb files or others where column adjustments and alignments are needed.
I tried awk but after substitution, the specific character spacing between columns is no longer preserved. You can specify your output to be comma or tab or space separated etc but you cannot retain specific character spacing between different columns. I believe that is a drawback of awk.
Maybe you could demonstrate what you mean as the limitation would mainly be on what is written so far ... not on awk.
As for sed, although it can retain column spacing after substitution, but if I place it in a loop over all the variables I want replaced, it performs substitution multiple times on the same original file, resulting in only the last value of the variable being substituted in the output. One way around is to keep creating temporary files for each substitution, with the next substitution working on the previous output temporary file.
I'm not sure if this is the issue to your problem but it looks like the file keeps getting overwritten because of '>' character. Try replacing it with '>>'. So I would change this.
Code:
#!/bin/bash
# Script to alter position of residue number in pdb file for resid above 999
i=$(awk '{print $5}' wt-test.pdb | uniq)
for i in $i;
do
if [ "$i" -gt "999" ]; then
sed 's/ $i / $i/g' wt-test.pdb > wt-test-out.pdb ;
fi
done
to
Code:
#!/bin/bash
# Script to alter position of residue number in pdb file for resid above 999
i=$(awk '{print $5}' wt-test.pdb | uniq)
for i in $i;
do
if [ "$i" -gt "999" ]; then
sed 's/ $i / $i/g' wt-test.pdb >> wt-test-out.pdb ;
fi
done
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.