Post

Text editors, and processing text streams through filters

Text editors, and processing text streams through filters

Here’s a complete and structured guide for:


📝 Text Editors, Text Streams, Filters, and Redirection


1. 🔤 Vi vs Vim

Featurevivim (Vi IMproved)
AvailabilityAlways installedMay require install (sudo apt install vim)
FeaturesBasic editingSyntax highlighting, undo, plugins, multi-level undo
UsageLightweightPowerful and extensible

Basic vi / vim Usage:

CommandAction
iInsert mode
EscExit to command mode
:wSave
:qQuit
:wq or ZZSave and quit
:q!Quit without saving
ddDelete line
yyYank (copy) line
pPaste line

2. 🔁 Output Redirection & GNU Text Utilities

ToolExampleDescription 
catcat file.txtPrint file contents 
cutcut -d: -f1 /etc/passwdCut fields by delimiter 
sortsort file.txtSort lines 
uniq`sort file.txt | uniq`Remove duplicates 
expandexpand file.txtConvert tabs to spaces 
joinjoin file1 file2Join files by common field 
splitsplit -l 100 fileSplit into chunks 
wcwc -l file.txtLine/word/char count 
sedsed 's/foo/bar/' fileStream edit 
head / tailhead -n 10 fileShow first/last N lines 

3. 🔗 Streams, Pipes, and Redirects

SymbolDescription 
>Redirect output to file (overwrite) 
>>Redirect output to file (append) 
<Redirect file to command input 
` | `Pipe: output → input of another 
teeOutput to screen and file: `cmd | tee file.txt` 
xargsPass input as command arguments: `cat list.txt | xargs rm` 

4. 🔍 Search with Regular Expressions

ToolDescriptionExample 
grepBasic searchgrep "error" logfile 
egrepExtended regex (same as grep -E)`egrep “foo | bar” file` 
fgrepFixed string search (no regex)fgrep "text" file 
sedSearch and replacesed 's/old/new/g' file.txt 
Regex examples   
.Any character  
*Zero or more  
^Line start  
$Line end  
[abc]Match a, b, or c  
[^abc]Not a, b, or c  
\dDigit (in grep -P)  

This post is licensed under CC BY 4.0 by the author.