Search This Blog

Friday, May 24, 2013

shell script with options

http://www.mkssoftware.com/docs/man1/getopts.1.asp


EXAMPLE
This is an example of using getopts in a shell script. Compare it to the getopt example.

# Example illustrating use of getopts builtin. This
# shell script would implement the paste command,
# using getopts to process options, if the underlying
# functionality was embedded in hypothetical utilities
# hpaste and vpaste, which perform horizontal and
# vertical pasting respectively.
#
paste=vpaste # default is vertical pasting
seplist="\t" # default separator is tab

while getopts d:s o
do case "$o" in
d) seplist="$OPTARG";;
s) paste=hpaste;;
[?]) print >&2 "Usage: $0 [-s] [-d seplist] file ..."
exit 1;;
esac
done
shift $OPTIND-1

# perform actual paste command
$paste -d "$seplist" "$@"

Thursday, May 23, 2013

How to make DHDall.xyz

#!/bin/bash

DHDfile=($(ls -1 DHD?????.xyz))  # Read all files of DHD?????.xyz
interval=$1        # Interval is the first argument.
: ${interval:=1}   # If there is no argument, default value is 1.


if [ -f DHDall.xyz ] # If DHDall.xyz exist
then
   rm DHDall.xyz     # then delete it.
fi
touch DHDall.xyz     # As DHDall.xyz is absent, touch it.

for (( i=0; i < ${#DHDfile[@]} ; i=i+$interval )) do
   cat  ${DHDfile[$i]} >> DHDall.xyz
done
exit








Friday, May 17, 2013

fortran file append


This partial code is to open existing (OLD) file, DHD00000.xyz, and write (APPEND) additional information from the end of the file

open(unit=1,file='DHD00000.xyz',status='old',position='append')
 write(1,*) "Here we go!"
close(1)

stop
end




Labels

Bacteria

Loading...