Products
Services
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: (3305)
Favorites:

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

#!/bin/sh
# Change character i for u
myexample="fill"
echo $myexample | tr 'i' 'u'



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

 Code Snippet 2

#!/bin/sh
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:
*Email:
*Description and Code:
*Enter Code shown
to the right:

[ Refresh Image ]