_                    _
  ___ | |__   __ _ _______ | |_
 / _ \| '_ \ / _` |_  / _ \| __|
| (_) | | | | (_| |/ / (_) | |_
 \___/|_| |_|\__,_/___\___/ \__|

text processingtools

sed : text stream editor, commonly used for substitution.
cut : split string.
tr : translate characters.
paste : join files/lines.
awk : pattern processing language.

replace old with new : s/old/new/
replace all occurrences : s/old/new/g
replace the second occurrence : s/l/p/2

$ echo "hello" | sed "s/l/p/"
heplo
$ echo "hello" | sed "s/l/p/g"
heppo
$ echo "hello" | sed "s/l/p/2"
helpo

-d | delimeter
-c | split by character count
-d | split by character (specify delimeter)
-f | specify field count. Use n,-n,n-
-f 2, gets 2nd field; -f -2, gets up to the 2nd field; -f 2-, gets from the 2nd field to the end
$ echo "a b c" | cut -d " " -f 2
b
$ echo "a b c" | cut -d " " -f 2-
b c
$ echo hello | cut -c 2
e

$ echo "hello" | tr "l" "m"
hemmo

echo "hello" | tr 'e' '\n'
h
llo
echo 'hello' | tr 'l' '\t'
he	o

echo 'hello' | tr 'h-l' 'a-d'
aeddo

echo '1.hello\n2.goodbye' | tr '[:digit:]' 'a-c'
b.hello
c.goodbye

Requires a file on OpenBSD, cat be a pipe redirection on Slackware.

$ cat test.log
1
2
3
$ paste -s -d "+" test.log
1+2+3

cat test.log | paste -s -d +
1+2+3
head : Get first 10 lines of file : head FILENAME
head -15 : Get first 15 lines of file : head -15 FILENAME

tail : Get last 10 lines of file : tail FILENAME
tail -15 : Get last 15 lines of file : tail -15 FILENAME
tail -f : Get latest lines of file continuously : tail -f FILENAME

Get lines matching pattern : grep PATTERN FILE(S)
Get lines not matching pattern : grep -v PATTERN FILE(S)
Get file names not matching pattern : grep -L PATTERN FILE(S)
Get line numbers matching pattern : grep -n PATTERN FILE(S)
Case-insensitive search for pattern : grep -i PATTERN FILE(S)
Recursive search : grep -R PATTERN DIRECTORY

- Translate to Spanish.
- review and improve if needed.

openbsd, slackware
OpenBSD manpages: paste(1), tr(1), head(1), tail(1), grep(1)

(back to top)

2026-06-02 : Fixed name: text_manipulation > text_processing.
2025-10-03 : Created

(back to top)

ohazot | about | ohazot.com <admin@ohazot.com>

2026-06-02