Thursday, November 5, 2009

Unix Commands

1. basic:
vi temp.sas:
edit mode for temp.sas;
more temp.sas:
view temp.sas:
read only;
rm temp.sas: delete temp.sas [rm ~\$zzz.doc (delete temporary file)];
mkdir test:
create directory called test;
rmdir test:
remove directory test, test needs be emptied first;
rm -r test:
remove directory test, test doesn't need to be emptied first;
cd ..:
go to the directory one level up;
cd tmpdir:  
go to directory called tmpdir;
cp temp.sas temp1.sas:
copy temp.sas as temp.sas;

2. save+quit:
:ZZ-->at the end of edit line; or,
:wq;
:x;

3. quit w/o saving:
:e! (still in the edit windows)
:q! (quit edit windows)

4.
1).
            change delete/cut copy
__________________________________________
1 letter         r      x          yl
5 letter         5s     5x         5yl
1 word           cw     dw         yw
5 words          5cw    5dw        5yw
1 line           cc     dd         yy
5 lines          5cc    5dd        5yy
to line begining c0     d0         y0
to line end      c$     d$         y$
3 words back     3cb    3db        3yb

2).
__________________________________________
move to line 6:                 :6 or 6G
change aaa to bbb on line 2:    :2s/aaa/bbb;
to the beginning:               0;
to the end:                     $;
10 letters lowcase<-->upcase:   10~;
Join 5 lines:                   5J;
insert:                         i or a;
repeat:                         .;
paste:                          p;
top line of screen:             H;
last line of screen:            L;
middle line of screen:          M;
find aaassss:                   /aaassss; n;

3). combinations:
delete     copy      from cursor to
__________________________________________

dH         yH        top of screen
dL         yL        end of screen
dG         yG        end of file
d+         y+        next line
d13G       y13G      13 line

4). recover large delete (upper to 9):
"1p: recover last deletion
"5p: recover fifth-to-last deletion
5). name own buffer (upper to 9):
"add: delete current line and save in buffer a;
"a7dd: delete 7 lines from current cursor position and save in buffer a;
"a7yy: copy 7 lines from current cursor position and save in buffer a;
"ap: paste buffer a information from current cursor position;
6). ex editor:
:3,18d    delete lines 3 through 18;
:3,18m23  move lines 3 through 18 after line 23;
:3,18co23 copy lines 3 through 18 and paste after line 23;
:=        total line number;
:.,$d     delete current line ( . ) to the end of file ( $ );
:20,.m$   move line 20 through current line ( . ) to the end ( $ );
:%d       delete all lines ( % );
:%co$     copy all lines ( % ) and paste to the end ( $ );
:-,+co0   copy three lines to the top (0);
:230,$w temp.sas   save 230 to end as temp.sas;
:.,600w temp.sas   save current line to line 600 as temp.sas;
:r /temp/data.sas  copy file data.sas in directory /temp and paste from current cursor position;
:e#      switch two open file back and forth;
:e!      return to original unsaved version;

7). global replacement:
:%s/run/jump/g     replace all run with jump;
:2,10s/jump/run/g  replace all jump from line 2 to 10 with run;
:2,10s/jump/run/gc replace all jump from line 2 to 10 with run, but need confirm;
:%s/./\U&/g        change to --> UPPERCASE;
:%s/./\L&/g        change to --> LOWERCASE;
:.,+5s/$/?/        add "?" at the end of 6 lines from current line;
:g/^/mo0           reverse the order;
:v/Paid in Full/s/$/Overdue/     if there is no "Paid in Full" on the line, will append a "   Overdue" at the end of the Line;
:%s/^/ >  /      add " >  " at the beginning of each line;
:%s/^/   /       add "   " at the beginning of each line;
:%s/$/ <  /      add " <  " at the end of each line;
:%s/^ *\(.*\)/\1/  delete all leading space of each line;
:%s/\(.*\) *$/\1/  delete all ending space of each line;
:g/^$/d            delete all blank lines;

8). advanced editing:
:set ic          search is no case sensitive;
:set noic        search is case sensitive;
:set window=50   50 lines each screen;
:!date           give date and time;
:r !date         read date to file;
:r !sort aa.sas  sort aa.sas and paste all from current cursor;

9). print: (c-tasc specific)
hp45 -z1 temp.lst
hp45 -z1 -p17 temp.lst
hp45 temp.lst

10). home/xxx/programs/subdir
grep neopt *.lst |more

11).
cp /home/xxx/programs/subdir/*.*  .
cp ../xxx/*.*  .
compress *
uncompress *

12). 
chmod 751 temp.sas: change read only mode to edit mode;
chmod 770 temp.sas: allow group members to access;
chmod g+s pgmsdir: allow directory access;

13). more memory requisition to run sas:
-memsize 256m -work /lv10/tmp temp.sas

14). 
cal --> show calendar;
spell a.sas --> show misspelled words;
df --> show free space;
who --> who is log on;
date --> show current date & time;

15). set up timer for auto run:
crontab -e
00 05 06 11 * /lv06/sas91/sas /home/xxxxx/programs/temp.sas
(close editor using :wq)

The above command will submit a sas program called temp to run at 5:00AM on November 6. The general format of the crontab command is minute hour day-of-month month weekday (Sunday is 0).

00 15 * * 1-5 /lv03/sas82/sas /home/dlxxx/somejob.sas
4 45 11 28 9 * /usr/local/sas/SASFoundation/9.3/sas /sasdata/ltrc/reports/temp.sas

16). Search for file with a specific name in a set of files (-name) 
find . -name "*conf" -print

This command will search in the current directory and all sub directories for a file ending with conf

Note: The -print option will print out the path of any file that is found with that name. In general -print will print out the path of any file that meets the find criteria. 

17). Use ls to create a sas file
ls . > temp.sas

This command will create a sas file temp.sas, which includes all the directory names, file names under current directory. Replace directory name with . to create file for other directory. 

18). Use diff to compare two sas files
diff program1.sas program2.sas

No comments: