So I've been banging my head against this for a few hours () and I can't see whats wrong with it, each part seems to work fine on its own when entered at command line, but then it falls down when pulled together.
I'm writing a script to translate fractional atomic coordinates to cartesian coordinates, itself a simple mathematical thing, but the input format is giving me trouble. The code should read in a .xyz file, which has 2 comment lines and then so many lines of atom x y z like so
48
Optimisation video
H 1.0000 1.0000 1.0000
C 1.2000 1.3000 1.3333
.
.
.
48
Optimisation Video
H 1.2000 1.2000 1.2000
C 2.0000 2.0000 2.0000
.
.
.
before being repeated (two comment lines etc) in a number of frames ($NoFrames), building up an animation of how the atoms move.
Ultimately I need to pull out each atom line and disregard the comment lines. I thought what I'd written (below) should do that but for some reason my sed -n statement always pulls out the comment lines as well
I've stripped all the code back to this, If i can get this part to work i can send the values off to be processed and then written into the output (Cartesian.xyz) file. Any help with this would be greatly appreciated and I hope I've made the problem as clear as I can, but please do tell me if I need to elaborate on something.
From your text, it seems that given input like this:
You want an output file (Cartesian.xyz) to contain:
I also assume that the transformation can be applied to each line independently (i.e. you don't need the whole frame's worth of data to do the transformation. If that is true, then might I suggest something along the lines of the following script to read and transform the data. Looking at your code, it seems to me you are doing a lot of unnecessary rereading of the input file with each loop skipping what has already been processed.
Again, this was just a guess at what your goal is, and a big assumption that each atom's coords can be translated independently of the others in the frame.
As for the transformation. I stuck in a dummy function to illustrate it. I don't know if you have an external programme that needs to be called, or if it's a function in your script that computes the transformation. Regardless, the assumption that I made was that the process/function echoes the changed x,y,z values which can then be echoed by the statement in the while loop.
Hope this makes some sense, and that I'm not too far off the mark.
With regards to your sed statement:
In this case the sed statement will regard the input files as a concatenated input stream, so if you print line 2 for example it will only be line 2 of the first file, because if the files are 100 lines long for example, the second line in file 2 would be line 102 to sed...
These 2 Users Gave Thanks to Scrutinizer For This Post:
Agama, Scrutinizer thanks for your posts, The bulk of the program involves stripping away ascii formatting from the output file of a scientific package and is all written in bash, so I'lll translate that concept into bash and get back if there are any major issues, thanks very much for taking time to help!
Hi folks,
I have a scenario to convert the update statements into insert statements using shell script (awk, sed...) or in database using regex.
I have a bunch of update statements with all columns in a file which I need to convert into insert statements.
UPDATE TABLE_A SET COL1=1 WHERE... (0 Replies)
Hi all,
i need a equivalent for the statement i run in bash, so it would also run in other shells. Specially i need it for ksh to run on AIX.
Here the statements:
exec > >(tee -a $log)
exec 2> >(tee -a $log >&2)
Thanks. (5 Replies)
I have the following code in bash, however "set red frmt" is not displayed.
echo "iarg_rd = $iarg_rd"
iarg_rd="2"
if ; then
echo "Hello World"
fi
if ; then
frmt="${gap}${!frmt_titl_yl}"
elif ; then
frmt="${gap}${!frmt_titl_bk}"
elif ; then
echo... (2 Replies)
Hi Gurus,
I have the below BASH code which does not works for upper case alphabets except Z (upper case Z).
What may be the reason. Also escape sequences like \n, \t, \b, \033(1m \033(0m (For bold letter) are not working.
case $var in
)
echo "Lower case alphabet"
;;
... (7 Replies)
Hi There,
I am trying to load data from a csv file into a DB during our DB migration phase. I am successfully able export all data into a .csv file but those have to rewritten in terms insert statement which will allow for further population of same data in different DB
My exiting csv record... (6 Replies)
Hey guys,
Currently trying to write a wee script that runs only when logged in as one of two users. The rest of the script is working fine, but no matter what user I try to run it as, it always fails! This is the puzzling part:if ]; then
echo "Run script as admin "
exit 1
else... (6 Replies)
Hi I need a script with an if statement that goes.
I need it to search through all files within a directory with the extension .test if it finds the string '71502FSC1206' then do
sed 's/71502FSC1206/\n&/g' > send.test
If it finds the string '715MCH' or '715JAC' then I need it to move the... (1 Reply)
I have the following bash script and it is not accepting the lines
"--"|"--""-")
"--""-"")
while
do
echo "Current Argument is ${1}"
case "$1" in
"--"|"--""-")
echo "Argument is ${1}"
shift # Skip ahead one to the next argument.
... (1 Reply)
Hi,
I need to escape slashes in my text, so I use this line:
search_string=`echo $var | sed 's@/@\\\/@g'`I expect that to replace a slash with a backslash followed by a slash. That works nicely, but it has a problematic side-effect. If there are two spaces in the var it replaces them with... (3 Replies)
I want to combine 2 conditional statements by using -o in bash, but it won't work.
if ; then
echo "The number needs to be between 0 and $nr"
fi
Each time i execute the file it says:
./selectCitaat: line 10: syntax error near unexpected token `$1' (3 Replies)