Sponsored Content
Full Discussion: G/AWK and ksh troubles
Top Forums Shell Programming and Scripting G/AWK and ksh troubles Post 302579543 by DEC014 on Tuesday 6th of December 2011 03:33:35 AM
Old 12-06-2011
G/AWK and ksh troubles

Alright, so I've been banging my head against the wall for the past 7 hours trying to figure this out Smilie. What I'm trying to do is "unwrap" periodic coordinates from a molecular simulation to put them back in their unit cell box. I've accomplished that little bit of magic easily enough, but I have to change the Unit Cell Vectors manually each time I want to run the program (see code below):
Code:
cat $project.xyz | gawk '
{ getline
    natoms = $1
        system("rm unwrapcoord")
    #print "Number of atoms/lines is: " , natoms
        getline
        for (i = 1; i <= natoms; ++i) {
                getline
                #print $0
                if ($2 > 26.680)
                        while ($2 > 26.680) {
                                $2 -= 26.680
                } else  while ($2 < 0) {
                                $2 += 26.680
                }
                if ($3 > 25.5422)
                        while ( $3 >= 25.5422 ) {
                                $3 -= 25.5422
                } else while ($3 < 0) {
                                $3 += 25.5422
                }
                if ($4 > 31.6148)
                        while ($4 >= 31.6148) {
                                $4 -= 31.6148
                } else while ($4 < 0) {
                                $4 += 31.6148
                }
                system("touch unwrapcoord")
                print $1, $2, $3, $4 >> "unwrapcoord"
                #print "New X: ", $2
                #print "New Y: ", $3
                #print "New Z: ", $4
        }
}'

And here is the first few lines of $project.xyz:

Code:
2250
$project.cif
C          4.68047        2.79457        0.68952
C          7.15344        2.79202        0.70501
C          9.58372        2.78180        0.67751
C         11.98973        2.76648        0.63293
....

What I am trying to do is set it up to where the shell script (or gawk, I'm not picky) reads the original CIF file to extract the Unit Cell Vectors and make everything automatic/streamlined. I can get the Unit Vectors into my ksh script using:
Code:
head -15 $project.cif | gawk '/_cell_length_a/ {print $2}'

but I can't seem to find a way to send this variable to GAWK or have gawk generate it on its own without messing up the rest of the unwrapping code.

Again, I've been at this for hours, and am hoping someone out there has got some ideas. Thank you to anyone that can help.

---------- Post updated at 02:33 AM ---------- Previous update was at 02:19 AM ----------

I know KSH has a "while read line" function built into it. But I couldn't find much information on it, and my Advisor told me that AWK is easier for parsing a file even if it is a bit slower in the math department. But I'm not opposed to writing everything in KSH using read line. So if that's an option, I'm ok with that. I just didn't know how to even try to use it.
 

10 More Discussions You Might Find Interesting

1. Programming

compiling troubles

i keep getting the following error with the code segment below when i try to compile the program. The code is from 'defs.h' parse error before '(' parse error before ')' stray '\' in program this is the code segment and the error is on the second line of the segment #define... (1 Reply)
Discussion started by: token
1 Replies

2. UNIX for Dummies Questions & Answers

compariosn troubles...

Hi Guys, I am trying to compare using if, but keep getting some strange results. if ; then keeps creating the file 1 if ; then does not work at all if ; then does not work if ; then does not work if ; then does not work eihter. I am using a ksh, on Solaris (9 Replies)
Discussion started by: jagannatha
9 Replies

3. Programming

Troubles with HPUX

Hello I created an application in c language for HP-UX operative system,and it runs on a 32 bits PARISC processor. My problem is that I have to run this same application but now in a 64 bits Parisc processor. But I am not able to compile the application with the 64 bit server, and I only could use... (1 Reply)
Discussion started by: masterboy6666
1 Replies

4. UNIX for Dummies Questions & Answers

ssh2 troubles

I'm trying to set up a secure and trusted connection between 2 boxes running solaris using ssh2. I've run ssh-keygen2 on the local box and on the remote box, created the identification file ( IdKey id_dsa_2048_a ) on the local machine and copied across the public key file from the local to... (5 Replies)
Discussion started by: PaulC
5 Replies

5. HP-UX

cron troubles

I have a cronjob that I need to run everyday and it needs to have todays date inputed, here is what I have, but is not working as expected.......... 23 02 * * * cd /path;./RequestSummaryReport.sh $(date +%Y-%m-%d) the output from mail gives me............. Date: Fri, 8 Feb 2008 02:12:07... (4 Replies)
Discussion started by: theninja
4 Replies

6. Shell Programming and Scripting

Encoding troubles

Hello All I have a set of files, each one containing some lines that follows that regex: regex='disabled\,.*\,\".*\"'and here is what file says about each files: file <random file> <random file> ASCII text, with CRLF line terminatorsSo, as an example, here is what a file ("Daffy Duck - The... (3 Replies)
Discussion started by: tukuyomi
3 Replies

7. UNIX for Dummies Questions & Answers

Cron troubles

I am aware this question has been answered time and again. I feel I have tried everything I have seen on the net and really need help to get this working. Same old story. Shell script, working from command but not from cron. I need my script to take values from a .properties file. Tried... (2 Replies)
Discussion started by: airalpha
2 Replies

8. Shell Programming and Scripting

awk and tr troubles

I am trying to make all the fields containing lower case letters upper case and the third field of a file display ** instead. I have this: awk '{printf "%s %s ** %d %d\n", $1, $2, $4, $5}' database.txt | tr '' '' < database.txt And that only changes it to upper case, other... (4 Replies)
Discussion started by: Bungkai
4 Replies

9. UNIX for Advanced & Expert Users

Troubles with OpenSSH

Hi, I am trying to login from one AIX server to another without using a password, a basic configuration, however it doesn't seem to work. All things are in place. I have both a public and private key in the ~/.ssh folder and also have an "authorized_keys" file on the target-server containing... (5 Replies)
Discussion started by: Hille
5 Replies

10. Shell Programming and Scripting

ksh passing to awk multiple dyanamic variables awk -v

Using ksh to call a function which has awk script embedded. It parses a long two element list file, filled with text numbers (I want column 2, beginning no sooner than line 45, that's the only known thing) . It's unknown where to start or end the data collection, dynamic variables will be used. ... (1 Reply)
Discussion started by: highnthemnts
1 Replies
suspend(1)                                                         User Commands                                                        suspend(1)

NAME
suspend - shell built-in function to halt the current shell SYNOPSIS
sh suspend csh suspend ksh suspend DESCRIPTION
sh Stops the execution of the current shell (but not if it is the login shell). csh Stop the shell in its tracks, much as if it had been sent a stop signal with ^Z. This is most often used to stop shells started by su. ksh Stops the execution of the current shell (but not if it is the login shell). ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWcsu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), kill(1), ksh(1), sh(1), su(1M), attributes(5) SunOS 5.10 15 Apr 1994 suspend(1)
All times are GMT -4. The time now is 05:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy