I recently had to write a little script that parsed virtual machines in XenServer, and since the names of the virtual machines consist mainly of white spaces, such as in Windows XP or Windows Server 2008, I had to trim these spaces and replace them with underscores _. I found a simple solution for this using sed, which is a great tool when it comes to string manipulations.
echo "This is just a test" | sed -e 's/ /_/g'
returns
This_is_just_a_test
bash sed
flazzarini Nov 10 '09 at 8:41 2009-11-10 08:41
source share