From: craig@pearl.thaad.lmms.lmco.com[SMTP:craig@pearl.thaad.lmms.lmco.com] Sent: Thursday, August 21, 1997 3:30 PM To: craig.j.simpson@lmco.com unix.txt 7/11/95 NOTES: UNIX, VI, VADS, SCRIPTS, SED, etc. ================================================================================ SEVEN DEADLY SINS Wealth without work Pleasure without conscience Knowledge without character Commerce without morality Science without humanity Worship without sacrifice Politics without principle - Mohandas Gandhi -------------------------------------------------------------------------------- ---------- Unix Commands ------------------------------------------------------- Unix is case sensitive; lower case should generally be used. COMMANDS MEANINGS apropos helps locate commands by keyword lookup apropos editor example: locates different editor commands alias show all alias's (equivalent to vms symbols) awk searches for records containing a particular string then performs a requested action {awk is not an abbreviation or acronym, e.g. no meaning} awk '{print $2 "," \ example: displays 2nd field "," 1st field $1 "^I" $3 people then tab then 3rd field of every record cal 1995 example: display calendar for all of 1995 cat types a file to the terminal, also concatenates files cat < temp temp1 example: redirects temp & temp1 to screen cat fname | mp -lo \ example: prints a file in the two page (landscape) | lpr -h mode (-lo), without the normal banner page (-h) cd change current directory cd /test/temp example: moves you to directory /test/temp cd example: w/o parameter, moves to home dir cd ~troy example: to get to troy's home directory chmod changes protection for a file chmod 644 filea example: 110100100 =rw-r--r-- =u:rw,g:r,o:r chmod u=w,g=rw,o=r filea example: explicit user, group, others chown change ownership of a file cmdtool -scale \ example: to spawn an independent (&) command tool large & proc., using large font(extra_large,medium,small) com to find common records in a file cp copy a file cp /etc/motd temp example: copies motd file in another dir to current directory, temp file cp /t/at /u/back . example: copy at and back to current dir date give current date and time dd copy and convert data dd conv=swab if=f1 of=f2 example: swap bytes, using f1 input & f2 output df to show disks !!!!! diff -c f1 f2 finds differences between files (w/ line before & after) echo $path example: displays "path" variable (search paths) egrep "(this|the)" a example: all lines with 'this' or 'the' in file 'a' file displays the type of file file /temp example: displays what type of file temp is find search-path expression to locate files or strings find . -name \ example: from current dir (.), finds all files "fname*" -print starting with fname (down through all subdirs), corresponds to vms: dir [...]fname*.* find ~ -size 0 -printexample: from home directory (~) down, find all files of 0 blocks, display(print) default dir. find . -name "*\.a"\ example: from cur. dir. down, find all files which -print are something + ".a" ('\' means use next symbol as a literal find . -type f \ example: from cur. dir. down, finds all files, -print | xargs \ excluding directories, which contain "word"; grep "word" equals 'search' in vms find . -type d -printexample: from current dir down, find all dirs. finger gives info about processes grep search for a particular string grep -v Sally pple example: all lines in pple which don't contain Sally grep -i the */*.a example: searches all ada files(*.a) in the first level subdir. of current dir., for "the" grep "a"||"b" fn example: find the line with 'a' or 'b'; &&=and; !=not groups to find out what group someone is in groups troy example: to find troy's group id history displays the previously entered unix commands, $history must be set & on, entering "!3" then executes the 3rd cmd. kill deletes an active process ln -s real-file link to establish symbolic "link" to "real-file" lpr to send a file to the printer lpstat to see the print queue (or use: lpq); to delete: lprm ls list the contents of the directory ls -al example: all subdirs & files(hidden), long format ls | grep -v ".*/" example: all nondir files ls -F example: add / for dirs, @ for symb link, * for exe ls -Rl | grep "^d" example: display all subdirs ('d' in column 1)<<<< ls -R | grep / example: another way for displaying subdirs<<<<<< ls -l | tee temp example: pipeline display to terminal & file ls -l > temp example: outputs results to temp file ls -R / example: displays contents of disk [...] ls -lc example: sorted by time of last modification mail enter ? to get a list of mail commands; "head 1"-lists first 20 messages; "head 21"-lists messages 21 upto 40 mail cc@Rat.COM < fn example: mail fn to cc@Rat.COM when sending do it from local processor, not titan man to get help on a unix system man mesg example: get help on mesg command man man example: "full-blown" description of man" mkdir create a directory mesg n prevents receiving any messages (via write or talk) more filea similar to type in vms, but more powerful (e.g. editor can be requested) {? or h requests help} mv renames a file passwd to set your password pr to prepare a file for printing printenv PATH display shell variable 'PATH', similar to: echo $PATH ps displays the status of your active processes ps al example: shows all processes, long form pwd print(show) working(current) directory pwd >> temp example: output (append) contents of current dir to temp, but don't destroy previous contents; temp must have existed previously (if not, use: "touch temp") rlogin remote login to another processor rm deletes files rm -i deletes files with confirmation rm -f deletes files whether write protected or not rm -r * delete every file from current dir down rm old.news bad.news example: delete 2 files rm -fr goodies.c \ example: f=don't ask for confirmation of removal; baddies.c r=recursively remove all entries from dir, then the dir rmdir deletes a directory rpl search and replace rpl "Sal" "Ed" \ example: replace 'Sal' with 'Ed' using the t.old t file & outputting to the t file rusers to find out the users on a network, corresponds to 'show users' on vms system screendump dump a frame-buffer image to a file set to see values for all variables which have been set set var1 to set var.; shown by: echo $var1, deleted by: unset var1 to perform arithmetic: @ var1 = 2 + $var3 set home = /u/craig example: setting var.; show by: echo $home setenv var1 example: setting var. for all processes sort +2 afile example: sort afile after field 2 source filename to execute script(filename) from inside another; this doesn't create new process, but entering filename not preceded by 'source' does split to split a file into multiple 1000 line files talk name@machine corresponds to phone in vms tar cvf /dev/nrmt1h .to write all files in current dir. to tape tar xvf /dev/nrmt0h to read files from tape top displays the processor usage, size, etc. of top processes, similar to monitor proc/topcpu in VMS touch filename updates access & modification times of a file; also, creates 0 length file, used with append, ">>", in scripts tr translate characters tr 'A' 'a' f2 example: using f1, substitute 'a' for 'A' & output to f2 tty find terminal name for window (unique for the window) umask 002 example: sets default file protection to 664=rw-rw-r-- unset echo to turn off echo wc counts the * of lines, words, or characters whatis displays a one-line summary about a keyword whatis ed example: display info about the editor which ada example: tells version of VADS to be executed who show who is on the system who am i info about your process; id's processor you are on who am i; date use of multiple commands on a line who | wc -l example: pipelining -finding # users by (displaying users, the output used to wc command to count the # of lines) write corresponds to 'phone' under vms write steve < temp example: sends steve the file temp (input for 'write steve' command was redirected to use temp as input @ var2 = 15 + $var1 example: adding const to variable; show by: echo $var2 !any_command does previous 'any_command' command ! = bang For the command: "who am i", who is the command and am & i are arguments. An option is usually preceded by a minus sign. An option modifies the action of the command or gives details of exactly how the command is to operate. Some options are preceded by a plus sign, some are not preceded by anything. The general order for a command is: command options expression filename(s) One book said single quotes (') and double quotes (") are used interchangeably. Another one said: " prevents all the shell's special characters from being interpreted except for $, ', and in certain cases \; while ' prevents all the shell's special characters from being interpreted. The 2nd version is correct. To continue a command on a new line use the back slash: "\" Paths are of the format: /main/ada/test/programs When you do an ls command, the "." means the current dir, the ".." means the dir above it, and "~" means the home dir. List all dirs on the the systems owned by root: find / -type d -user root -print Remove all files owned by the user jim: find / -user jim -exec rm -f {} \; To remove all core and dead.letter files older than one day: find / \(-name core -o -name dead.letter \) -mtime +1 -exec rm -f {} \; -----special characters----- \ nullifies the special meaning of any char. which immediately follows * represents any series of characters ? represents any single character ] [ - ^d logout signal to the shell ^s ^q stopping and re-starting output to the terminal ^c interrupt execution of the current command -----redirection-------------------------- File Descriptors: 0 is for standard input 1 is for standard output 2 is for diagnostic output Example: cat somefile 1> output 2> errfile --redirects normal output to outfile & diagnostics to errfile; using 2>/dev/null would discard diagnostics. Troy said: make |& tee afile--sends standard output and diagnostics to screen and 'afile' make >& afile --sends stand. out.(>) and diag.(&) to 'afile', no overwrite make > & ! file --causes 'file' to be overwritten(!) note: the '!' is needed if 'noclobber' var exists; use set cmd to check -----ftp (file transfer protocol)----- cd target_dir --set target dir for files ftp -i iap --where 'iap' was the processor where source dir is ftp> cd a_dir --set dir to source dir ftp> mget * --to copy all the files in source dir to current dir ftp> quit --to exit the ftp program ------------------------------------------------------------ To run command in the background mode add an &: nroff doc & To mail a message: mail henry We are meeting for lunch at ll:30 in the cafeteria. ^d To run a command at some future time: at 0230 calendar | mail maryann ^d or: at 1650 echo time to go home! | mail craig ^d -----interactive commands----- echo -n "Please enter your filenames: " --respond with: afile bfile cfile set names = $< --$names = "afile bfile cfile" set list = ($names) --$list[1] = "afile", etc. --In the above example you could also substitute in for the 2nd line: set names = `gets` --but, $names[1] = "afile", $names[2] = "bfile", etc. -----using grep----- To delete a record containing "Henry Morgan" & add a record containing "James Walker": $ grep Henry softpeople Henry Morgan 112 $ mv softpeople softpeople.old $ grep -v "Henry Morgan" softpeople.old > softpeople $ cat >> softpeople James Walker 112 ^d $ rm softpeople.old $ chmod 444 softpeople Using the grep (global regular expression printer) command. Examples: "Genesis" finds occurrences anywhere in the file "^Genesis" finds occurrences only in column 1 "Genesis$" finds occurrences only a the end of the line "^$" finds blank lines "do.." finds strings starting with "do" and having 2 more characters "do..\." as above except the word must be followed by a period "[Gg]ensis" finds both Genesis and genesis "^[0-9]" finds any line beginning with a numeric character "D.*" finds strings of characters of any length, starting with 'D' -----using awk----- Example of using 'awk': In a file called average we have: $ cat >average display cat, but for each line {total = total + $3} add the 3rd field to the total END {print "Average score is ", total / NR}at end, display & compute the ^d average (total / # of records) $ nr is a "built-in" variable Now we enter the command: $ awk -f average tennis which executes the awk command in the tennis file using the average file as a command file (-f option) to provide the following output: Average score is 8.9 Another use of awk (with the same file as above) is to display all records ($0 means the whole record) which contain a score of 10 or more (in the 3rd field): $ awk '$3 >= 10 {print $0}' tennis For a file with records of the format: year price wine_type the following awk command can be used: $ awk '$1 ~ /197[5678]/ && $2 <= 8.00' chardonnay This command selects all records whose first year is in the range 1975..1978 and whose price is less than $8. The ~ means "match" and the && means that both conditions must be true. Two alternative ways of giving the same cmd: $ awk '/^197[5678]/ {if ($2 <= 8.00) print $0}' chardonnay $ awk '$1 >= 1974 && $1 <=1978 && $2 <= 8.00' chardonnay -----command line scripts----- >foreach file (*.a) --for each *.a file in dir., echo & rename ?echo $file --c-shell knows after first line you have more to ?mv $file $file.o --enter, therefore, the change in prompt ?a.app -s $file.o $file --ada call to eliminate preporcessor directives ?end --"end" finishes script, then back to normal prompt > --instead of "*.a", could use "`cat list`" to use --a file of filenames as input -----paste----- If files a, b, & c contain 1 word lines and the contents are -- a: one,two,three b: 1,2,3; c: A,B,C; then 'paste a b c' would output lines: one 1 A two 2 B three 3 C In other words, line 1 of each file are concatenated, then line 2, etc. -------------------------------------------------------------------------------- ---------- View (vi) Editor ---------------------------------------------------- To recover a file: vi -r file-name General format for VI commands: [count]operator[count]object O, o, i, a, c, r, s get you into text entry mode. ESC gets you out of text entry mode and into vi command mode. From vi command mode, : gets you into ex command mode. ESC or return gets you from ex command mode into vi command mode. ex command mode commands: :wq or : or ZZ exits you from the editor (updates kept) :quit! quits the editor (updates discarded) :$ -takes you to the end of the line :432 -takes you to line 432 :/ -when followed by search string, locates string, cursor placed at beginning of line :w -write (update) file, but keeps editor (no quit) :e! -re-edit current file (discarding changes) :e fn -edit file named fn :f -to see filename and line :g/old/# -display all occurrences of "old" on screen :n! -edit next file (discarding changes in cur file) :3,8d -delete lines 3 through 8 inclusive :2,5m9 -move lines 2 through 5 to after line 9 :w fn -writes buffer to file named fn :s/old/new/ -substitute new string for old on current line :!date -execute unix date command :map -corresponds to LSE define key :map = (iNote: ^[ -example: insert "Note:" in front of sentence; note: ^[ = ESC is done by pressing CTRL-V then ESC type = initiates the map sequence :sh -gets you to unix shell, CTRL-D returns to vi :s/old/new/g -perform sub. for each occurrence on current line :1,$s/*//g -for every line (1,$) substitute all (g) *'s with nothing :%s/old :set all -show all options :set ignorecase -ignores case in searches using regular exp :set autoindent -auto starts new line at same col as previous :set number -display line numbers :set nonumber -do not display line numbers :set list -display invisible characters<<<<<<<< :set nolist -return to normal display :set sw = 2 -sets shift to 2 spaces; >> or << performs shift of line; . will repeat last command; >) shift sentence :set tabstop = 4 -resets all tabs to four characters :set wrapmargin = 5-automatically inserts "\n" when a space or tab occurs within 5 spaces of the right margin vi command mode commands: 3dw -delete three words u -undo the previous command dd -delete line fZ -example: finds next occurrence of "Z" in current line n -find the next occurence of the search string N -next occurrence in reverse direction :n -same as "n", except go to beginning of line ? -same as "/", but searches current line back to top of file / -when followed by search string, locates string, cursor placed at start of string // -performs search using previous string as search string x -delete a character nx -delete n characters ~ -change the case of the letter at cursor & move one space to right s -overstrike mode (doesn't seem to work on our sys) j -join two lines into one line yy -copy a line to edit buffer p -paste edit buffer in doc.(P does it before cursor) r -to replace one character R -strikeover mode ^f (CTRL-f) -page forward ^b (CTRL-b) -page backward mx -mark a point in the document as "x" my -mark a point in the document as "y" `x -return to "x" mark (` is same key as ~, but without shift) ^L -when in insert mode, inserts a form feed (page break) Moving a paragraph from one file to another: In original file, place cursor on line before paragraph. Delete para. placing it in buffer "b" by: "bd} If needed, write original file to disk: :w Go to new file: :e! new_file_name Place cursor at insertion point. Retrieve para. (in buffer "b") by: "bP w=word, ( or ) = sentence, repeating d or y = line, { or } = paragragh d=delete, y=yank (copy), p=put example: dd=delete line, d}=delete from cursor to end of paragraph -------------------------------------------------------------------------------- ---------- ED Editor ----------------------------------------------------------- ED commands (commands are very similar to VI, except VI is a screen editor and ED is a line editor): e -(enter) goto a new file, discard the previous buffer contents a -(append) puts you in insert mode for typing new text . -if in insert mode, typing a period in col. puts you back in cmd mode i -insert p -(print) display the current line 1,$p-(print) display all lines of the current file 3p -(print) display the third line // -search for a string ?? -backwards search for a string k -mark a line d -delete a line m -move a line t -transpose = -display current line number v/^$/p -displays all non-blank lines /toad/s/bumps/smooth/-find line w/"toad", then perform substitution /bread/s//wheat &/ -for next line w/"bread", substitute in "wheat bread" /head/s//shoulder/ -for line with "head", substitute in shoulder Example series of ed commands: * /Steve/ -find line with "Steve" Steve Daniels 111 * ka -mark that line as "a" * /ark/ -find line with "ark" Hank Parker 114 * 'a,.p -display lines from "a" mark to current line Steve Daniels 111 Sylvia Dawson 112 Hank Parker 114 -------------------------------------------------------------------------------- ---------- Verdix System ------------------------------------------------------- DEBUGGER INFO (from using the debugger): --------------------------------------- a --advance / step over b --when cursor is at wanted location ...will set a breakpoint bd --break down; break at return from current routine bx --break at exceptions cs --call stack d --delete breakpoints; e.g. d all or d 2 (lb to list brkpnts) e --(enter) move to a new source file examine --display program elements and components exit --terminate the debugger session g --(go) continue executing gw --(go while) continue until a var. changes (watchpoint)<<< help --print help text I --assembly/source code toggle l --(list) display part of a source program, e.g. l 10, 5 -list 5 lines starting at line 10 lb --list breakpoints load --dowload memory image to the target lt --list all active tasks p --when cursor is at wanted variable ...will display var. value q --return to line mode from visual mode quit --terminate the debugger session Q --switches debugger from screen to line mode; vi to return r --restart the program from the begining read fn --read debugger commands from file 'fn' s --step into set case off --make / & ? searches not case sensitive set except_stack --aid in debugging set source dn --set dir search path (dn) debugger uses to find files vi --for visual (or screen) mode; Q to return to line mode --re-execute debugger command :aray(1):a--display address of array 'aray' :b loc --will set a breakpoint at 'loc' :b begin p an_array(1..3) end --for source code, displays array ele. on break :bi if ($t6 >= 04C) then p a_var end --for asmbly, displays var. on break --when condition is satisfied :p var --will display the value of 'var' := --assignment., e.g. var := 10.00 (except enumeration, use day := 1, --not day := monday !!!!! +number --move forward 'number' of lines, e.g. +5 -move 5 lines forward number --move to line number 'number' Command Line Commands: ^u --erase the entire text on the command line ^h --erase last character (backspace) --change from insert mode to edit mode k --(while in edit mode) go back (up) in history 0 --(while in edit mode) move cursor to beginning of line $ --(while in edit mode) move cursor to end of line i --(while in edit mode) enter insert mode Screen Mode Commands: --print next window of text --print next line g --enlarge command window (at expense of source window); windows restored by next debug cmd or by window control cmd C q --do not display remaining output but enter it in history buffer and log to specified file p --turn off paging for both debugger commands and program output x --abort debugger command (stop program output by stopping the program with ---- --move backward one screen numberC --change 'number' of lines in the window, C restores original sizes #--scroll down '#' of lines, or half a window --scroll foward one screen --print name of file displayed in source window n --repeat previous search [[ --move forward in source to next proc., func., pkg., or declare block --redraw all windows /string --search foward for 'string' : --enter a debugger command , --move to the other window 0 --move to beginning of line --halt "the program being debugged" Notes: 1) * is the current home position for the file 2) = there is a breakpoint at the line from Debugging Ada programs in Verdix Ada Development System, book 1: -------------------------------------------------------------------- a.path to show ada library linkage a.db options executable --to execute the debugger options: -v --screen mode invoked, Q will return to line mode filename --direct output to filename >&filename --direct output & error msgs to filename alternative, run debugger & enter: set input my_prog.i load r quit to set output, use: set run < filename ***stopped at page UG 6-6 -------------------------------------------------------------------------------- ---------- THAADS -------------------------------------------------------------- Target processors: RS3000 Host processor: DECstation 5000/240. Contact phone number for Rational is 800/433-5444. Lockheed Fax #: 408/756-2495. E-mail address can be found by creating a new window; just append the prompt to craig@, for example: craig@saturn.ese.lmsc.lockheed.com -------------------------------------------------------------------------------- ---------- Misc. Commands ------------------------------------------------------ col/row/c /r order qpr -ls -Con -G 2 2 0 r downright -B1 filename --to print 4 per page alias cd 'cd \!*;set prompt="$eff_id""<`pwd`>\! "' alias icgrep 'grep -i' qpr -P local filename --to print on other printer (in landscape) lpr (print) command options which don't seem to work on our printer: -Dpostscript --for post script input -#n --where n is the # of copies to be printed -Ksides --where 'sides' is 1 or 2 -Nn --where n is # pages on a sheet -Oorientation --where orientation is landscape or portrait pr -l65 -s -o10 filen | qpr -p -d --print portrait(p), double-sided(d), --don't truncate end of line(s), offset(o), 65 lines per page(l) To shut down the DECstation towards powering off, logon using "shutmeup" as both the id and password. -------------------------------------------------------------------------------- ---------- Writing Unix C Shell Scripts ---------------------------------------- 1. To write a c-shell script there must be a '#' in the first character of the first line (& maybe nothing else?). {'#! /bin/sh' for borne shell scripts} 2. Comments are started with '#', but I had a problem with entering a string of '-' on a comment line. 3. Command line parameters, e.g.: a.dbt param1 param2 In the alias, in the script, for 'a.dbt', you might have: alias a.dbt 'mv -f tlog alog; \a.db -L $loc -i \!:1 \!:2; err llog | tee t' a) '\!:1' would receive the first parameter: 'param1', etc. b) the '\' means don't look for an alias c) there are 3 command executed by this alias d) '$loc' must have been defined previously in a set statement: set loc = /usr3/users/craig/scripts e) if only one parameter was used in an alias, then you could have put '\!*' instead of '\!:1' 4. To execute a script in the current process: 'source scriptname' or in a child process, just: 'scriptname' 5. To convert a normal file into a script, change the protection to execute: chmod +x scriptname 6. Examples of script files in: usr/users/troy/troys.environment/bin 7. There is a problem with 'source'ing a script which includes a parameter, in an alias, e.g.: alias lpr 'source $dirs/lpr.s \!*' -- will not run. The solution is to set the input parameters, before sourcing: alias lpr 'set filename = \!*; source $dirs/lpr.s' -----example C shell scripts-------------- 1. script to read a file which contains a list of files: foreach i (`cat filelistfile`) #loop thru each filename in the file sed -f change.sed $i > ! $i:t.a #see note1 & note2 echo "sput $i" #display the filename sput $i << sccs_reason #sccs put, with reason new b3v1.4 with b2v8.7 telemetry #the text of the reason sccs_reason end #note1: on file 'i', execute stream editor (sed) using change.sed file # & output to 'i.a'. '!' means write even if file exists. ':t' # means tail only(not path) (for filename), see variable modifiers. #note2: -f means use the following file for edit commands # -e means use the following script for edit commands 2. script showing case (switch) statement: # this program matches one of two files if ($#argv == 0) then echo "No argument declared" exit endif switch ($argv[1]) #or use: 'switch $1' case FILE1: echo "You have selected FILE1" breaksw case FILE2: echo "You have selected FILE2" breaksw default: #or use: 'case *:' echo "You must select either FILE1 or FILE2" breaksw endsw 3. cycle thru all input parameters: # shift arguments to the left foreach words ($argv[*]) shift echo $argv end #example usage: script_file input_param_1 input_param_2 input_param_3 4. cycle thru all input parameters (another way): for x do echo "compiling: $x" ada $x done #example usage: script_file file_1 file_2 file_3 file_etc -----C shell script info---------- 1. list becomes a list of files with $1 extension ($1 is input parameter): set list = `ls -rt *.$1` foreach this_file ($list) ... end 2. argv is the array of input parameters. For 'lpr p1 p2 p3', argv would have size of 3 and #argv would be 3; argv[1], argv[2], argv[3] would have values p1, p2, & p3. Parameters can be referenced either by $argv[n] or $n, e.g. $argv[5] or $5. $0 is the command itself, but cannot be referenced by using $argv[0]. 3. for a script which requires 2 inputs, the following confirms 2 inputs: if $#argv != 2 then echo 'this script requires 2 inputs - infile & outfile' else ... endif 4. to test for existence of 'var': if ($?var) then ... or: if $?var == 1 then ... 5. to test for non-exist of 'var': if !($?var) then ... 6. \rm -this would by-pass any previously set alias for rm (e.g. rm -i), therefore, the pure rm command would be executed. 7. if (-e $1) then... #would check for existence of file id'd by $1 8. date +"%m %d %y" #executes the unix date command, using the given #format string (see 'man date'). 9. @ count++ #increments 'count' variable by 1 10.set array = (0 0 0) #declaring & initializing 3 element integer array set words = (at a be) #declaring & initializing 3 element string array ----Variable Modifiers----- :r -root name; :h -header name; :t -tail; :e -tail(BSD only); :q -quote set fname = $2:t'_&_'$1:t #if $1=/b/that & $2=/a/this then fname=this_&_that #and $2:h=/b -----File Checking----- -e -true if file exists; -z -true if 0 size; -f -true if ordinary file; -d -true if directory; -o -true if user owned; -r -true if readable; -w -true if writable; -x -true if executable # script which detects file existence and length = 0 if !(-e $1) then echo file does not exist else if -z $1 then echo file is zero length endif -------------------------------------------------------------------------------- ---------- Sed Commands -------------------------------------------------------- WARNING: This info is very condensed. Several sed functions may be displayed on a line...be careful when applying this. Sed (stream editor) commands act on a whole file. In a sed script, each command will be executed on the whole file. Format: sed -e 'command' -e 'command' infilename > outfilename or sed -f command_file infilename > outfilename -------Examples:----- sed '/^--/d' a > b #delete all lines starting with '--', input 'a' output 'b' sed -n '20,30p' a>b #print only lines 20 thru 30 sed '1,/^$/d' a>b #delete up to & including first blank line sed '[^ ]/5/g' a>b #substitute 5 for all ('g') occurrences of non-blank char. -------Sed commands (within a sed command file: sed -f fn ...):----- /^--/d #delete all lines which start with '--' (^=start of line) s/:.*$// #delete from leftmost ':' to the end of the line ($=end of line, .=any single character, *=any # of previous character) s/^/p / #insert 'p ' at the start of the line 2d #deletes line 2 h #copies current line into a hold buffer g #get contents of hold buffer & place in current line /;$/{ #find all ';' which are at the end of the line N #do the following commands on that location s/\n/ / #substitute new-line character with blank (join 2 lines) } #end of command group 1. First, find a line which begins '>p'. For that line (1) at col 1 sub '>' for '>p' (2) operate on next line as well (3) sub ':= ' for new line character(\n) /^>p/ { s/^>p/>/ N s/\n/:= / } -------Sed commands (executed from unix command line):----- 1. Delete all 'ada_dir/' in 'this_file' ('#' is used as separator): sed 's#ada_dir/##g' this_file > that_file 2. Find a line which starts with a lower case character preceded by any number of blanks: sed -n -e '/^ *[a-z]/p' this_file > that_file '-n' -don't print line unless requested, '^ *' -start in column 1 & match any number of blanks, '[a-z]' -any lower case char., 'p' -print the line -------Sed command file:----- 1i\ #insert 2 lines separate (AVN_TPC_TRA_F2F_CSU) \ procedure Initialize is s/$/;/ #add semi-colon to every line s/ azs /S_Frame_Azimuth/ #change variable name s/obj( *\(9\) *,\(8\)/OBJ(\2,\1)/ #change obj( 9 ,8) to OBJ(8,9)* s/-\.\([0-9]*\)/-0.\1/ #change -.# to -0.#, e.g. -.98 to -0.98 /Ada/{ #find line which contains 'Ada' h #copy it to hold buffer p #print it s/da/ba/p #print the line, subbing 'ba' for 'da' g #grab the hold buffer again s/da/za/p #print the line, subbing 'za' for 'da' d #don't print the hold buffer } $a\ #add last line end Initialize; *The \( and \) combination means save what's inside. For the example there are 2 occurrences (9 and 8) and they would be labeled 1 and 2. They are then referenced by \1 and \2 when they are put back into the string in reverse order. -------------------------------------------------------------------------------- ---------- Writing Gawk Scripts ------------------------------------------------ If we want to add "--SPR xxxx" to each line of a file such that the line will always be 80 characters and the above suffix string will appear at the end of the line, then we could use the following command line call: gawk -v spr_num="1205" -f insert_spr.awk YOUR_INPUT_FILE > YOUR_OUTPUT_FILE to the following gawk script: # file_name=insert_spr.awk--------------------------------------------------- BEGIN { #set-up data max = 80 #max length of string + suffix string_size = 10 #size of the suffix string astring = "--SPR " spr_num #the suffix string } # { #perform following on each line if (length < max) #if string is not too long { # pad_size = max - length - string_size #number of blanks to add to line pad = " " # for (i = 1; i <= pad_size; i++) { # pad = pad " " #build blanks string } # print $0 pad astring #print original string + blanks } # string + suffix string } # END { #to do any tasks after proc. all } #lines of the file - do it here Additionally, you could add the following script (put_spr.s): # gawk -v spr_num=$1 -f insert_spr.awk $2 > $2.suffixed and then use the following command line call: put_spr.s 1205 YOUR_INPUT_FILE -------------------------------------------------------------------------------- ---------- Interleaf ----------------------------------------------------------- To bring up interleaf, in Session Manager window select Applications menu & Interleaf entry. The right mouse button is used to select things. The middle button is for bringing up a menu. To create a new drawer (linked): 1. select system V cabinet (right button) 2. copy/link/original object (middle button) 3. paste it where you want it (middle button for menu, then right button) 4. open properties (middle button) 5. change: a)name -put cursor in box, press left button, start typing, example: Troy b)pathname -same as 'a)', example: /usr/users/troy/desktop c)icon class -put cursor in box, push/hold down center button, select 'drawer' To create help: 1. on desktop, with nothing selected, press middle button 2. select custom 3. select toolmgr 4. select (left mouse button) button to left of "Interleaf", a menu appears 5. for a menu entry, on the far right is a button with a "0" on it; press the button to change it to a "1" 6. press center mouse button and select apply 7. select symbol to immediate right of entry to open up a window discussing usage of the selected tool. This window will tell you how to start up the tool you want; e.g. tutorial or reference. There is no functional difference between folder, drawer, and cabinet. There is an error in the tutorial, in Formatting & Editing, Component Proper- ties, from Exercise 3 to 4, the change you make is erased, therefore the menu Exercise 4 tells you to go into is not available. There is another error in the tutorial, in Formatting & Editing, Search & Replace, Exercise 3, you are told to enter replace string, but search string remains blank. -------------------------------------------------------------------------------- ---------- Writing Tapes: from unclassified to classified system -------------- -----At unclassified system:----- 1. insert the tape --use 1/4" size tapes, low (150mg) -- density 2. rlogin apollo --only processor with 1/4" drive 3. cd your_dir_with_files_to_transfer 4. tar cvf tar.file * --combine the files into one file 5. compress tar.file --compress the file 6. mt -f /dev/nrmt0l rewind --rewind the tape 7. tar cvf /dev/nrmt0l tar.file.Z --copy the compressed file to tape 8. mt -f /dev/nrmt0l rewind --steps 8 & 9 are optional - used to 9. tar tf /dev/nrmt0l -- confirm what's on the tape -----At classified system (Sim Lab):----- 10. insert the tape 11. rlogin mamba --only proc. with byte-swap capability 12. cd an_empty_dir --to write the tape files to 13. mt -t /dev/tapens rewind --rewind the tape again 14. tar xvf /dev/tapens --tapens driver does required byte swap- -- ping because of incompatible systems -- dec versus silicon graphics 15. uncompress tar.file.Z --uncompress the tape file 16. tar xvf tar.file --separate into apporpriate files tar cvf /dev/tape tar.file --c=create new tape,v=verbose,f=use name that follows as the name of the archive, x=extract files ---------- From Pearl to Moonbeam (STL) ---------------------------------------- For 8mm tapes, substitute in the following steps: -----At a Pearl window:----- 6. mt -f /dev/rmt/0 rewind 7. tar cvf /dev/rmt/0 tar.file.Z Note: to not rewind tape after an operation use: /dev/nrmt/0 ---------- From Titan to Pluto (Software Test Lab) ----------------------------- For 8mm tapes, substitute in the following steps: -----At a Titan window:----- --delete steps 2, 8, 9 6. mt -f /dev/nrmt0h rewind --rewind the tape 7. tar cvf /dev/nrmt0h tar.file.Z --copy the compressed file to tape -----On Pluto (Software Test Lab):----- --delete step 11 13. mt -t /dev/nrmt1h rewind --rewind the tape again 14. tar xvf /dev/nrmt1h --read in files from tape -------------------------------------------------------------------------------- ---------- Word For The Day ---------------------------------------------------- "But why do we fantasize at all? Blame biology. Like all animals, we have a genetically encoded need to propagate our species. For women, the best way to do this is to copulate with one male and then bear and raise his offspring. For men, it's our evolutionary burden to want to copulate with anyone who sits to pee." --Dan Greenburg