Sponsored Content
Top Forums Shell Programming and Scripting [BASH] Problem with a sed -n statement Post 302599836 by EdinburghLad on Saturday 18th of February 2012 09:38:57 PM
Old 02-18-2012
[BASH] Problem with a sed -n statement

Hey all,

So I've been banging my head against this for a few hours (Smilie) 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

Code:
# $NoFrames and $NoAtoms are defined earlier in the code and do not change
#
# Start of the systematic loop, outer deals with frames, inner with atoms
#
FrameNumber=0 # Used to know which line the sed statement should strip out
FrameCounter=1 # Keeps a track of which frame we're analysing
AtomCounter=1 # Keeps a track of which atom (within each frame) we're analysing
while [[ $FrameCounter -le $NoFrames ]]; do
        while [[ $AtomCounter -le $NoAtoms ]]; do
                let "AdjustedAtomCounter=(($FrameNumber*($NoAtoms+2))+($AtomCounter+2))" # This line should allow me to skip the first two lines per frame (the comment lines)
                sed -n "${AdjustedAtomCounter}p" *.xyz
                let "AtomCounter=$AtomCounter+1"
        done
echo $NoAtoms >> Cartesian.xyz
echo "Cartesian GeomOpt Video" >> Cartesian.xyz
let FrameCounter=FrameCounter+1
let FrameNumber=FrameNumber+1
let AtomCounter=1
done
rm *.txt
exit

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.

Cheers!
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Conditional statement in bash

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)
Discussion started by: doc.arne
3 Replies

2. Shell Programming and Scripting

Bash sed problem

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)
Discussion started by: RickS
3 Replies

3. Shell Programming and Scripting

Problem using bash case statement

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)
Discussion started by: kristinu
1 Replies

4. Shell Programming and Scripting

bash if statement help needed

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)
Discussion started by: firefox2k2
1 Replies

5. UNIX for Dummies Questions & Answers

Bash - OR within an IF statement

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)
Discussion started by: jimbob01
6 Replies

6. Shell Programming and Scripting

Awk/sed problem to write Db insertion statement

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)
Discussion started by: bhaskar_m
6 Replies

7. Shell Programming and Scripting

BASH - case statement

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)
Discussion started by: GaneshAnanth
7 Replies

8. Shell Programming and Scripting

[Solved] If statement in bash

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)
Discussion started by: kristinu
2 Replies

9. UNIX for Dummies Questions & Answers

Bash statement equivalent

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)
Discussion started by: Kosak
5 Replies

10. Shell Programming and Scripting

Convert Update statement into Insert statement in UNIX using awk, sed....

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)
Discussion started by: dev123
0 Replies
geom(1) 																   geom(1)

NAME
geom - analyzes a molecular geometry input in Cartesian coordinates. DESCRIPTION
The program geom reads a set of Cartesian coordinates and determines from them the bond distances (Bohr and angstrom), bond angles, tor- sional angles, out-of-plane angles (optional), moments of inertia, and rotational constants. FILES REQUIRED
input.dat - Input file and one of the following: geom.dat - geometry file file11.dat - PSI-format geometry/gradient file FILES GENERATED
geom.out - file containing the analysis INPUT OPTIONS
The geom program has the following options: -h Print help information (these options). -aces [filename] Read the input in an ACES output format, with each line consisting of atomic symbol, atomic number, and Cartesian coordinates (in Bohr). The optional argument is the name of the geometry input file, which defaults to geom.dat. -qchem [filename] Read the input in an QCHEM output format, with each line consisting of the atom number, the atomic symbol, and Cartesian coordinates (in Angstroms). The optional argument is the name of the geometry input file, which defaults to geom.dat. -xyz [filename] Read the input in an XYZ output format. The first line contains the number of atoms and the second line is a comment line. Subse- quent lines each contain the atomic symbol and Cartesian X Y and Z coordinates (in Angstroms). The optional argument is the name of the geometry input file, which defaults to geom.dat. -oop Print out-of-plane angles, where the angle a-b-c-d is defined as the angle formed by the vector a-d and the plane defined by atoms b, c, and d. DO_OOP = boolean Same as command-line switch -oop described above. ISOTOPES = matrix of reals/strings Used to specify masses to be used in the calculation of the center of mass and rotational constants. One array is provided for each isotopomer to be calculated. The arrays can mix floating point numbers with strings which designate isotopes. If this array is not given and file11.dat is present, then the masses will be obtained by converting the atomic numbers in file11. If masses are not given by ISOTOPES or by file11, then no mass-related quantities will be calculated. -g [filename] Read Cartesian coordinates from a file other than file11.dat. If a filename is not given, the default is geom.dat. The alternative file is assumed to be in a format similar to that of PSI's geom.dat. Since such files do not contain atomic numbers, the moments of inertia and rotational constants are not calculated if this option is used. READ_GEOM = boolean This option in input.dat tells geom to read the geometry from geom.dat in the PSI geom.dat format. -a Print parameters for all pair distances. PRINT_ALL_DIST = boolean Same as -a flag described above. -d distance Only print parameters involving pairs of atoms which are less than distance bohr apart (default value is 4.0 bohr). PRINT_DISTANCE = value Same as -d flag described above. -angstrom The input coordinates are in angstroms, not bohr. ANGSTROM = boolean If TRUE, the input coordinates are in angstroms instead of bohr. The default is FALSE. The following example is for calculating the geometrical information for water with several different isotopes. The geometry is read from geom.dat rather than from file11.dat. geom: ( read_geom = true isotopes = ( (O H H) (O D D) (O18 1.007825 1.007825) ) ) 5 June, 1998 geom(1)
All times are GMT -4. The time now is 11:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy