sed Flashcards
sed
sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).
sed
- e
- f
- E, -r
- s
- e script, –expression=script, Add the script to the commands to be executed.
- f script-file, –file=script-file, Add the contents of script-file to the commands to be executed.
- E, -r, –regexp-extended, Use extended regular expressions in the script.
- s, –separate, Consider files as separate rather than as a single, continuous long stream.
sed ‘ s/string1/string2/ ‘ file1.txt
This command substitutes and replaces the first occurance of string2 with string1.
sed ‘ s/string1/string2/2 ‘ file1.txt
This command substitutes and replaces the second occurance of string2 with string1.
sed ‘ s/string1/string2/g ‘ file1.txt
This command substitutes and replaces all occurences of string2 with string1. The /g stands for global.
sed ‘ s/string1/string2/3g ‘ file1.txt
This command replaces string2 with string1 from the third occurance and beyond. Any number can be added to that range.