Skip to content

gauravkr04/shellscripting

Repository files navigation

shellscripting

Practising Shell Scripting

Sed Editor

sed with -i : edit the file

sed without -i : will print the change on output

-e is for multiple coniditons in sed commands

-e cond 1 -e cond 2

1. Search and replace / Substitute

eg

sed -i -e 's/root/ROOT/g' 's/admin/ADMIN/g' sample.txt

2. Delete Lines

sed -i -e 'id' -e '/root/ d' sample.txt

3. Add Lines

sed -i -e '/root/ i Hello World' sample.txt

Examples

To search and replace root with ROOT

sed -i -e 's/root/ROOT/g' /tmp/passed

To delete the second line

sed -i -e '2d' /tmp/passed

To delete the line containing world ROOT

sed -i -e '/ROOT/d' /tmp/passed

To insert a new line at first place

sed -i -e '1 i Hello World' /tmp/passed

To append a new line after first line

sed -i -e '1 a New World' /tmp/passed

To replace the line with Hello Universe where the word World present

sed -i -e '/World/ c Hello Universe' /tmp/passed

To Interrupt on Shell prompt - CTL + C

To comment the selected text - CTL + /

To come out from Mongo Shell - CTL + D

To clear screen on Shell Prompt - CTL + L

About

Practising Shell Scripting

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages