Posted by: admin November 19, 2017 Leave a comment. 2 nd way – The slice object for getting the substring. Edit: Clarification. Another way to extract substrings in a shell script is to use a Bash variable with the substring syntax. sed to extract pattern between a substring and first occurance of numeric in a string. s - The substitute command, probably the most used command in sed. In this Bash Tutorial, we shall learn to compute substring of a string given starting position and length of substring.. Syntax. b=${a:12:5} where 12 is the offset (zero-based) and 5 is the length. How can I easily extract the substring before a specific character in Linux (bash, sed or awk ...) ? substring in Perl is little special compared to other languages due to some additional functionalities. (2) I am using basic sed expression :-sed -n "am/,/sed/p" to get the text between "am" and "sed" which will output "am \n using \n basic \n sed". somehow 'sed' doesn't know when to stop. Following is the content of a file: This option tells sed to edit files in place. 1. Recommend:regex - grep/sed/awk - extract substring from html code. # Usage: $0