User Tools

Site Tools


linux:shellcommands

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
linux:shellcommands [2017/04/18 09:38] – [rsync] adminlinux:shellcommands [2018/05/05 12:42] – [sed] admin
Line 362: Line 362:
   * new = the text to replace it with   * new = the text to replace it with
   *g = global (i.e. replace all and not just the first occurrence)   *g = global (i.e. replace all and not just the first occurrence)
-Below are some basic examples:   +Below are some basic examples for searching and replaccing string<code bash>
-  * Example search and replace string<code bash>+
 cat intro cat intro
 +</code>output:<code>
 The Unix operating system. Unix system The Unix operating system. Unix system
- +</code> 
-sed 's/Unix/UNIX/g' intro  =>  Substitute Unix with UNIX+  * <code bash>sed 's/Unix/UNIX/g' intro </code>  =>  Substitute Unix with UNIX
 The UNIX operating system. Unix system The UNIX operating system. Unix system
- +  * <code bash>sed --in-place 's/Unix/UNIX/g' intro </code> =>  Substitute Unix with UNIX in file intro 
-sed --in-place 's/Unix/UNIX/g' intro  =>  Substitute Unix with UNIX in file intro +  * <code bash>sed 's/Unix/UNIX/g' intro </code>  =>  Substitute Unix with UNIX
- +
-sed 's/Unix/UNIX/g' intro   =>  Substitute Unix with UNIX +
-</code>+
   * example with -n option<code bash>   * example with -n option<code bash>
-sed -n '1,2p' intro        +sed -n '1,2p' intro</code>=> Just print the first 2 lines 
-=> Just print the first 2 lines +  * <code bash>sed -n '/UNIX/p' intro</code>=> Just print lines containing UNIX
- +
-sed -n '/UNIX/p' intro +
-=> Just print lines containing UNIX+
   * example Deleting Lines<code bash>   * example Deleting Lines<code bash>
 sed '1,2d' intro sed '1,2d' intro
-=> Delete lines 1 and 2 +</code>=> Delete lines 1 and 2 
- +  * <code bash>sed '/UNIX/d' intro</code>=> Delete all lines containing UNIX
-sed '/UNIX/d' intro +
-=> Delete all lines containing UNIX +
-</code>+
 ==== awk ==== ==== awk ====
   # cat server   # cat server
linux/shellcommands.txt · Last modified: 2022/10/29 16:15 by 127.0.0.1