function::text_strn - Linux


text_strn is a Linux command used to perform string manipulation and transformation operations. It primarily serves to locate specific text patterns within strings and replace them with user-defined substitutions. This command is particularly useful in text processing tasks, data extraction, and string modification scenarios.


text_strn [-c,--count NUM] [-h,--help] [-i,--IgnoreCase] [-o,--output FILE] [-r,--regex REGEX] STRING TEXT


  • STRING: The target string to be searched and modified.
  • TEXT: The replacement text to be used.


  • -c, –count NUM: Limits the number of substitutions to NUM. Default is to replace all occurrences.
  • -h, –help: Displays the help message and usage information.
  • -i, –IgnoreCase: Performs a case-insensitive search and replacement.
  • -o, –output FILE: Redirects the modified string to the specified file instead of printing it to the standard output.
  • -r, –regex REGEX: Uses the specified regular expression for pattern matching instead of a simple string.


Simple string substitution:

text_strn Java JavaScript



Case-insensitive replacement:

text_strn -i TEXT text



Regex-based pattern matching:

text_strn -r '[0-9]+' "the number is: #"


the number is: 42


the number is: #

Common Issues

  • Incorrect regex syntax: Ensure that the provided regular expression is syntactically correct.
  • Ambiguous patterns: Avoid using ambiguous patterns that may match unintended text.
  • Missing arguments: Provide both the STRING and TEXT arguments as they are essential for the substitution operation.


Combining with other commands:

  • grep: Use the modified string as input to grep for further filtering.
  • sed: Incorporate text_strn into sed scripts for complex text transformations.

Related Commands

  • grep: Search for specific patterns in text.
  • sed: Perform text editing and transformation operations.
  • awk: Process and manipulate data stored in text files.