General Startup To use vi: vi filename To exit vi and save changes: ZZ or :wq To exit vi without saving changes: :q! To enter vi command mode: [esc]
Counts A number preceding any vi command tells vi to repeat that command that many times.
Cursor Movement
h move left (backspace)
j move down
k move up
l move right (spacebar)
[return] move to the beginning of the next line
$ last column on the current line
0 move cursor to the first column on the current line
^ move cursor to first nonblank column on the current line
w move to the beginning of the next word or punctuation mark
W move past the next space
b move to the beginning of the previous word or punctuation mark
B move to the beginning of the previous word, ignores punctuation
e end of next word or punctuation mark
E end of next word, ignoring punctuation
H move cursor to the top of the screen
M move cursor to the middle of the screen
L move cursor to the bottom of the screen
Screen Movement
G move to the last line in the file
xG move to line x
z+ move current line to top of screen
z move current line to the middle of screen
z- move current line to the bottom of screen
^F move forward one screen
^B move backward one line
^D move forward one half screen
^U move backward one half screen
^R redraw screen ( does not work with VT100 type terminals )
^L redraw screen ( does not work with Televideo terminals )
Inserting
r replace character under cursor with next character typed
R keep replacing character until [esc] is hit
i insert before cursor
a append after cursor
A append at end of line
O open line above cursor and enter append mode
Deleting
x delete character under cursor
dd delete line under cursor
dw delete word under cursor
db delete word before cursor
Copying Code
yy (yank)'copies' line which may then be put by the p(put) command. Precede with a count for multiple lines.
Put Command
brings back previous deletion or yank of lines, words, or characters
P bring back before cursor
p bring back after cursor
Find Commands
? finds a word going backwards
/ finds a word going forwards
f finds a character on the line under the cursor going forward
F finds a character on the line under the cursor going backwards
t find a character on the current line going forward and stop one character before it
T find a character on the current line going backward and stop one character before it
; repeat last f, F, t, T
Miscellaneous Commands
. repeat last command
u undoes last command issued
U undoes all commands on one line
xp deletes first character and inserts after second (swap)
J join current line with the next line
^G display current line number
% if at one parenthesis, will jump to its mate
mx mark current line with character x
'x find line marked with character x
NOTE: Marks are internal and not written to the file.
Line Editor Mode
Any commands form the line editor ex can be issued upon entering line mode.
To enter: type ':'
To exit: press[return] or [esc]
ex Commands For a complete list consult the UNIX Programmer's Manual
READING FILES
copies (reads) filename after cursor in file currently editing
:r filename
WRITE FILE
:w saves the current file without quitting
MOVING
:# move to line #
:$ move to last line of file
SHELL ESCAPE executes 'cmd' as a shell command.
:! 'cmd'
Thursday, September 10, 2009
vi command
Posted by joe is my nick name at 4:05 AM 0 comments
Tuesday, September 8, 2009
how to use awk | substr
hi all,
herewith i have a flat file (test.txt) below :
test.txt :
CTI-ProgramStart|VVV2|Program Start|VKGXXXXXXXX|VKGXXXXXX|06/01/22 00:33:49.467|WSSACCCXXXX|VVV21137XXX3|B Program Version:.6.4.5 AgentID:2247 Password: Signature: Extention:7950 PeripheralID:2 SideAHost:109.XX.XX.XX SideBHost:192.XX.XX.XX SideAPort:42027 SideBPort:5874 HEARTBEATINTERVAL:-1 EXPECTEDCLIENTS:150 QUEUESIZE:32 POOLSIZE=64 SERVICESMASK:-214749088 EVENTSMASK:311071 STATUSMASK:1031 TRACEMASK:5|
i would like to get ext = 7950
BEGIN {
FS="[|]"
}
$1 == "CTI-ProgramStart" {
if( match($9, /Extention:[0-9][0-9]*/) ) {
str=substr($9, RSTART, RLENGTH)
ext=substr(str, index(str, ":")+1)
print ext
}
}
Note : u have to read the flat file fisrt before insert the algorithm.
Labels: shell script
Posted by joe is my nick name at 4:16 AM 0 comments
how to display date yesterday at unix
if u want to display date yesterday at unix with format YYYYMMDD, you can try with my script below :
if u type at unix shell with syntac date, so the result is below :
bash-3.2$ date
Tue Aug 18 08:41:44 wib 2009
we can change the format as our need. example i need format yyyymmdd.
please make script below and save to tanggal_hari_ini.sh
run as below
sh tanggal_hari_ini.sh
Input Script :
#!/usr/bin/bash
# bof date
month=`date +%m`
day=`date +%d`
year=`date +%Y`
month=`expr $month + 0`
day=`expr $day - 1`
if [ $day -eq 0 ]; then
month=`expr $month - 1`
if [ $month -eq 0 ]; then
month=12
day=31
year=`expr $year - 1`
else
case $month in
1|3|5|7|8|10|12) day=31;;
4|6|9|11) day=30;;
2)
if [ `expr $year % 4` -eq 0 ]; then
if [ `expr $year % 400` -eq 0 ]; then
day=29
elif [ `expr $year % 100` -eq 0 ]; then
day=28
else
day=29
fi
else
day=28
fi
;;
esac
fi
fi
case $month in
[0-9]) month="0$month";;
esac
case $day in
[0-9]) day="0$day";;
esac
yesterday=$year$month$day
echo $yesterday
# eof date
exit 0
output script : 20090818
Labels: shell script
Posted by joe is my nick name at 1:42 AM 0 comments
Monday, September 7, 2009
swap columns and replace
hi, any problem manipulating (swap coloumn n replace)
example :
File sebelum.txt
1A6Y173BPHE-75.1167.5
1A6Y174BGLY58.7155.7
1A6Y175BARG-18.1142.6
1A6Y176BILE-72.6136.1
1A6Y177BPRO-68.1-136.2
1A6Y178BLYS-162.6360.0
sould be :
File sesudah.txt
1A6YB173PHE-75.1167.5
1A6YB174GLY58.7155.7
1A6YB175ARG-18.1142.6
1A6YB176ILE-72.6136.1
1A6YB177PRO-68.1-136.2
1A6YB178LYS-162.6360.0
you can do it with this script
cat sebelum.txt awk 'BEGIN { FS=""; OFS="" } {$a=$2 $2=$3; $3=$a; print $0 } ' >> sesudah.txt
Note :
FS = Field Sparator
OFS = Output Field Sparator
Labels: shell script
Posted by joe is my nick name at 8:16 PM 0 comments