2
# substring-extraction.sh
7
# Note different string indexing system:
8
# Bash numbers first character of string as 0.
9
# Awk numbers first character of string as 1.
11
echo ${String:2:4} # position 3 (0-1-2), 4 characters long
14
# The awk equivalent of ${string:pos:length} is substr(string,pos,length).
16
{ print substr("'"${String}"'",3,4) # skid
19
# Piping an empty "echo" to awk gives it dummy input,
20
#+ and thus makes it unnecessary to supply a filename.
27
{ print index("'"${String}"'", "skid") # 3
28
} # (skid starts at position 3)
29
' # The awk equivalent of "expr index" ...