Linux Sed Regular ExpressionsStream EditorThe sed command is used for stream editing. Example: Look at the above snapshot, string 'interactive' is changed to 'distractive' with sed command. Inspite of forward slash (/), colon (:), underscore (_) and pipe (|) will also work. Interactive EditorThe sed command is meant to be stream editor while it can also be used as interactive editor on a file. For interactive editor option 'i' is used. Example: Look at the above snapshot, stream 'today' is converted into 'tomorrow' in the 'file'. Simple Back ReferencingDouble ampersand is used to search and find the specified string. It will print the found string with sed command. Example: Look at the above snapshot, ampersand has searched the string 'four' and printed it as 'fourfourty'. A Dot For Any CharacterIn regex a simple dot can signify any character.,/p> Example: Look at the above snapshot, dots are replaced by the date format. Multiple Back ReferencingWhen more than one pair of parenthesis is used it is called grouping. Here each of them can be referenced separately as three consecutive numbers. Example: Look at the above snapshot, date is printed in different formats. Here, 2014 is referenced as (1), 06 is refernced as (2) and 30 is referenced as (3). White SpaceThe white space syntax is '\s' and tab space syntax is '\t'. Example: Look at the above snapshot, '\s' is used for a single space. Optional OccurrenceYou can specify something optional by specifying it with (?) question mark. Example: Look at the above snapshot, we have made third 'i' as optional. It mens that two 'i' are must to be converted into 'Y'. Exact n Times OccurenceExact times occurence is specified by "{times}". Example: Look at the above snapshot, we have specified exactly three times occurence of 'i'. Occurence In RangeWe can specify occurence in terms of range also. For example, if we'll specify range as {m,n}, then 'm' denotes minimum times occurence and 'n' denotes maximum times occurence. Example: Look at the above snapshot, we have specified minimum range as 3 and maximum range as 4.
Next TopicLinux File OwnerShip
|