echo "Greater than symbol puts the console output in a new file." echo "Two greater than symbols puts the console output at the end of an existing file." echo "Format of sed is s as a command forward slash to indicate a regular expression" echo "and then the replacement in slashes." echo "Line 1 ORIGINAL">text.txt echo "Line 2 a. ORIGINAL b. original c. ORIGINAL">>text.txt sed -i 's/ORIGINAL/SUBSTITUTE/' text.txt cat text.txt echo "Press enter to continue" read Foo sed -i 's/SUBSTITUTE/ORIGINAL/' text.txt echo "Doing glogal replace ( multiple times on a line ) with g option." sed -i 's/ORIGINAL/SUBSTITUTE/g' text.txt cat text.txt echo "sed is case sensitive"
At a console you can enter "man sed" without the quotes to see how the sed utility works. The option -i means to edit files in place and can be used to create a backup if needed. Many more useful options are available and this is just a simple example of the use of this utility. You can cut and paste this into a script as a demo to test it for yourself. It is easier for me to understand when I change things and see how they work. I changed this today to read "press enter" instead of "any key".
0 comments:
Post a Comment