![]() usr/local/sbin:/sbin:/bin/:/usr/sbin: /usr/bin/local:/opt/omni/bin: usr/kbos/bin:/usr/local/bin:/usr/jbin/: /usr/bin/local:/usr/sas/bin Example 1 – sed & Usage: Substitute /usr/bin/ to /usr/bin/local $ sed path.txt The precise part of an input line on which the Regular Expression matches is represented by &, which can then be used in the replacement part. opt/tools/bin:/opt/omni/sbin:/root/bin II. In this sed example, the delimiter ‘/’ was escaped in the REGEXP and REPLACEMENT part. ![]() ![]() When you should use ‘/’ in path name related substitution, you have to escape ‘/’ in the substitution data as shown below. opt/tools/bin:/opt/omni/sbin:/root/bin Example 2 – sed / delimiter: Substitute /opt/omni/lbin to /opt/tools/bin usr/kbos/bin:/usr/local/bin:/usr/jbin/:/usr/bin:/usr/sas/bin In the sed example below, in the last line of the input file, /opt/omni/lbin was changed to /opt/tools/bin. When you substitute a path name which has ‘/’, you can use as a delimiter instead of ‘/’. opt/omni/lbin:/opt/omni/sbin:/root/bin Example 1 – sed delimiter: Substitute /opt/omni/lbin to /opt/tools/bin usr/local/sbin:/sbin:/bin/:/usr/sbin:/usr/bin:/opt/omni/bin: usr/kbos/bin:/usr/local/bin:/usr/jbin:/usr/bin:/usr/sas/bin Let us first create path.txt file that will be used in all the examples mentioned below. In this article, let us review some interesting workarounds with the “s” substitute command in sed with several practical examples.Īs we discussed in our previous post, we can use the different delimiters such as % | : in sed substitute command. In our previous sed articles we learned - sed printing, sed deletion, sed substitute, sed file write, and sed multiple commands. This article is part of the on-going Unix Sed Tips and Tricks series.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |