-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtext_manipulation.bash
More file actions
28 lines (22 loc) · 840 Bytes
/
text_manipulation.bash
File metadata and controls
28 lines (22 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Text Manipulation
# Use grep for look for patterns in your file
grep "pattern" file.txt
# Example you can look for "errors" in a log file
grep "error" logfile.log
# Use sed for replace patterns or words
sed 's/pattern/replacement/' file.txt
# Example replace 'foo' with 'bar' in a file
sed 's/foo/bar/g' file.txt
# awk its a powerful text processing and reporting tool. It works with structured text files
# (likes CSV files)
# Example: to print the first column of a text file
awk '{print $1}' file.txt
# Basic regular expression
# . Matches any single character except newline
# * Matches zero or more ocurrences of the proceding character
# ^ Matches the beginning of a line of a line
# $ Matches the end of a line
# [abc] Matches any single character a,b or c
# \ Escapes a special character
# Example
grep ^abc' file.txt