Contact Us

Scripts: Unix :: String Processing :: Library Article #1

Developer's Section

Basic String Operations
By: Erobo Team Member

Hire a Developer for Related Work / Installation | $55 hr
Rating:  | Rate It:   
Average Votes: (3028)

Learn Basic string operations in Unix such as concatenation and substrings.

Unix Strings:

Bourne Shell
we can use translate "tr" to change characters within a variable. Example:

 Code Snippet 1

# Change character i for u
echo $myexample | tr 'i' 'u'

Use "sed" to eliminate trailing space and tabs in a string:

 Code Snippet 2

myexample2="this is    another example on strings."
cat $myexample2 |\
sed 's/[    ][ ]*//g' |\ 
sed 's/[.]/ period /g' 

In the last example we take the string, eliminate spaces and tabs, and replace the period (.) for the actual word "period".

See other Scripts in String Processing

Submit Your Scripts:

If you would like to have your Unix scripts published in this section please fill out
the form below:
*Your Name or Username:
Home Town:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]