Bash - sub,gsub

regex Using: sub , gsub -> (Global sub)

  • sub (pattern, replacement, x)
  • gsub (pattern, replacement, x)
sub ("little", "big", "Mary has a little lamb.") 
# Substitutes ONLY the first occurrence of the word "little" by another word "big".

“Mary has a big lamb.”


  • sub(pattern, replacement, x, ignore.case = FALSE, fixed = FALSE, useBytes = FALSE)

  • gsub(pattern, replacement, x, ignore.case = FALSE)