UNIX-1.4 Sort and Sed Commands

Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: facebook.com/fuzicast
twitter: @fuzicast
youtube: youtube.com/yuejdesigner85

sort – sort file
sort -t, -k1 file1 – sort file1 by column 1, delimited by comma (,)
sort -r -t, -k1 file1 – in reverse
sort -n -t, -k1 file1 – sort by numerical value
sort -f file1 – case insensitive sort
sort -t’|’ +0 -2 – sort by the first 2 fields, starting from 0+1th field and end at 2nd field.

sed – special editor
sed ‘s/pattern/replacement/gi’ – search and replacement globally and case insensitively
sed ‘s/pattern/&replacement/gi’ – & represents the pattern found
sed ‘s/\(group\)pattern/\1/gi’ – \1 contains value of 1st group
sed ‘s/hello/bye/2g’ – replacements second occurrence of hello
sed ‘/pattern/p’ – will print out occurrences of pattern
sed -e ‘command1’ -e ‘command2’ – run multiple commands
sed ‘s/'”$VAR”‘/replacement/’ – using external variables in sed
sed ‘2 s/pattern/replacement/’ – replace only for line 2. you can also specify line range, 1,10
sed ‘/pattern1/ s/pattern2/replacement/’ – find pattern1, for those lines, replace pattern2 with replacement
sed ‘/start/,/end/ s/pattern/replacement/’ – using patterns as line number range. you can also mix line number with pattern
sed ‘1,10d’ – deletes line 1 to 10. you can also mix pattern range as well
sed ‘100,$d’ – delete from line 100 to end of file
sed ‘100,$!d’ – delete from line 1 to line 100. ! means inverse operation.
sed ‘y/ABC/abc/’ – replacement each character with corresponding characters

regular expression
[0-9a-z]* – match 0 or more alphanumeric characters
[0-9a-z]+ – match 1 or more alphanumeric characters
[^a-z] – any character does not contain a-z

Collection of Color Schemes for VIM Editor (256-color compatible)

Awesome colors, Awesome schemes








Planned Videos In Production

VIM-1.3 More VIM Commands
I will introduce the rest of VIM commands, vimdiff commands and we will be done with VIM commands. There are a lot more commands out there, but I only want to go through the most practical ones. 

VIM-1.4 VIM Configurations and Color Schemes
Learn how to configure VIM to use it like a charm, such as autoindent, tab size, search highlight and etc. Then we will move on to color schemes where you can customize your VIM editor to have your favorite theme and specific language syntax highlights. 

VIM-1.5 Installing VIM Plugins
I will demonstrate how to install Java plugins and Perl plugins. You will find it enjoyable to code with all the plugins available. Make sure to try out more plugins yourself.

And that concludes VIM series. Next I will continue on UNIX videos, covering hundreds of commands and shell script syntax. So stay tuned! :)

VIM-1.2 VIM Commands

Make sure to subscribe to my channel for more videos on UNIX, Perl and SQL.
facebook: http://www.facebook.com/fuzicast
twitter: @fuzicast

:x – save and quit
ctrl + z – bring editor to background
fg – bring back editor
~ – change character case
U – undo all the changes to that line
vi” – select content between quotes for that line
ctrl+v, select multiple “print” statements on multiple rows, press s, then type “say” statement, press esc and enter
shift + v – highlight whole line, move up and down to select multiple lines
y – copy highlighted lines
p – paste whatever copied from y
yy – copy whole line
select multiple lines and search replace
>> – shift right
<< – shift left
V + – shift multiple lines
V + d – delete multiple lines
:sav filename – save as another file
A – append at the end of line
:r filename – reads in another file and appended to the cursor
‘. – go back to the last edit position
view – read-only mode
:!command – execute unix command inside vim
:r! command – read in output from command
w – go to next word
b – go to previous word
w filename – writes highlighted lines to a file
:set nu – view line numbers
dw – delete characters up to empty space
cw – same as dw, but enters insert mode
:e! filename.txt – discard current file and changes, start editing new file
vimdiff file1 file2 – check differences between 2 files
ctrl +w twice – get to next split screen
:sp filename – split screen on filename
:vsp filename – vertical split screen on filename
:tabnew – open new tab
:tabm3 – rearranging your tab
gt – go to next tab

VIM-1.1 Vim Editor Introduction

Here are a list of VIM commands used in this video:
i – insert mode
a – append and insert
s – replace and insert
o – create new line and insert
:set number – display line number
esc – return to command mode
gg – go to first line of file
G – go to last line of file
:100 – go to line 100
:.,$d – delete all lines between current cursor to end of file
D – delete from cursor to end of line
J – concatenate 2 lines
/pattern – forward search for pattern
?pattern – backward search for pattern
$ – go to end of line
0 – go to beginning of line
:wq – save and quit
:q! – quit without saving
:e! – restore all changes since opening of file
n – find next match
N – find previous match
ZZ – save and quit