Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Last revision Both sides next revision | ||
help:general_linux:linux_advanced [2016/05/18 13:35] jebailie created |
help:general_linux:linux_advanced [2016/05/18 14:16] jebailie [awk] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ===== Linux Commands : advanced=== | + | ===== Linux Commands : file - search / replace |
+ | For the following cmds, the // | ||
+ | < | ||
+ | 1 cat barn food | ||
+ | 2 dog house kibble | ||
+ | 3 fish water food | ||
+ | 4 cow pasture grass | ||
+ | </ | ||
==== grep ==== | ==== grep ==== | ||
+ | " | ||
+ | * Good for searching a file for a certain pattern | ||
+ | < | ||
+ | user@tim:~$ grep --help | ||
+ | Usage: grep [OPTION]... PATTERN [FILE]... | ||
+ | Search for PATTERN in each FILE or standard input. | ||
+ | // snip // | ||
+ | | ||
+ | user@tim:~$ grep cat test.file | ||
+ | 1 cat barn food | ||
- | ==== diff ==== | + | user@tim:~$ grep food test.file |
+ | 1 cat barn food | ||
+ | 3 fish water food | ||
+ | |||
+ | </ | ||
==== awk ==== | ==== awk ==== | ||
+ | " | ||
+ | |||
+ | * good for printing columnar data, note that the field separator (between the columns) can be anything (space, tab, colon, etc) and can be specified with -F | ||
+ | < | ||
+ | user@tim:~$ awk ' | ||
+ | cat | ||
+ | dog | ||
+ | fish | ||
+ | cow | ||
+ | </ | ||
==== sed ==== | ==== sed ==== | ||
+ | " | ||
+ | < | ||
+ | user@tim:~$ sed s/cat/lion/ test.file | ||
+ | 1 lion barn food | ||
+ | 2 dog house kibble | ||
+ | 3 fish water food | ||
+ | 4 cow pasture grass | ||
+ | |||
+ | (note that the input file // | ||
+ | |||
+ | user@tim:~$ cat test.file | ||
+ | 1 cat barn food | ||
+ | 2 dog house kibble | ||
+ | 3 fish water food | ||
+ | 4 cow pasture grass | ||
+ | |||
+ | user@tim:~$ sed s/cat/lion/ test.file > new.file | ||
+ | (save into // | ||
+ | |||
+ | user@tim:~$ cat new.file | ||
+ | 1 lion barn food | ||
+ | 2 dog house kibble | ||
+ | 3 fish water food | ||
+ | 4 cow pasture grass | ||
+ | |||
+ | user@tim:~$ cat test.file | ||
+ | 1 cat barn food | ||
+ | 2 dog house kibble | ||
+ | 3 fish water food | ||
+ | 4 cow pasture grass | ||
+ | </ | ||