> You script worked for me on Ubuntu 10.04 with bash 4.1-2ubuntu3. > > - Bill
Hmmm - that's odd. When I run it on my box I lose the leading spaces. Debian Squeeze/Sid, bash 4.1.5(1)-release (x86_64-pc-linux-gnu) I guess I need to take a looksee into the Ubuntu version and see if I can figure out what they're doing... Thanks anyway for your help. Regards, Ozz. > On Tue, Nov 23, 2010 at 1:17 PM, <[email protected]> wrote: > >> Hi Guys. >> >> I have a text file where some lines contain leading spaces. >> I need to modify the file with cat, sed and echo. >> This is causing leading spaces to be lost. >> >> Here is a sample of the relevant section of the text file (it is part of >> the config file for a xen guest): >> ============= >> root = '/dev/xvda2 ro' >> disk = [ >> 'phy:/dev/volgrp/www3-swap,xvda1,w', >> 'phy:/dev/volgrp/www3-disk,xvda2,w', >> ] >> ============= >> >> >> and here is the relevant section of the script I currently have: >> ============= >> #!/bin/bash >> SUCCESS=0 # Value used to test for goodness. >> cat /home/ozz/Scripts/temp/www3.cfg | >> while IFS='' read -r line >> do >> echo "$line" | grep -q "xvda2,w" >> if [ $? -eq $SUCCESS ] >> then >> echo "$line" >> /home/ozz/Scripts/temp/www3.cfg.tmp >> ( >> cat <<'EOF' >> 'phy:/dev/volgrp/www3-var,xvda3,w', >> 'phy:/dev/volgrp/www3-tmp,xvda4,w', >> 'phy:/dev/volgrp/www3-home,xvda5,w', >> 'phy:/dev/volgrp/www3-home-logs,xvda6,w', >> EOF >> ) >> /home/ozz/Scripts/temp/www3.cfg.tmp >> else >> echo "$line" >> /home/ozz/Scripts/temp/www3.cfg.tmp >> fi >> done >> mv -f /home/ozz/Scripts/temp/www3.cfg.tmp >> /home/ozz/Scripts/temp/www3.cfg >> >> ============= >> >> >> Desired result: >> ============= >> root = '/dev/xvda2 ro' >> disk = [ >> 'phy:/dev/volgrp/www3-swap,xvda1,w', >> 'phy:/dev/volgrp/www3-disk,xvda2,w', >> 'phy:/dev/volgrp/www3-var,xvda3,w', >> 'phy:/dev/volgrp/www3-tmp,xvda4,w', >> 'phy:/dev/volgrp/www3-home,xvda5,w', >> 'phy:/dev/volgrp/www3-home-logs,xvda6,w', >> ] >> ============= >> >> Actual result: >> ============= >> root = '/dev/xvda2 ro' >> disk = [ >> 'phy:/dev/volgrp/www3-swap,xvda1,w', >> 'phy:/dev/volgrp/www3-disk,xvda2,w', >> 'phy:/dev/volgrp/www3-var,xvda3,w', >> 'phy:/dev/volgrp/www3-tmp,xvda4,w', >> 'phy:/dev/volgrp/www3-home,xvda5,w', >> 'phy:/dev/volgrp/www3-home-logs,xvda6,w', >> ] >> >> ============= >> >> I've GTFW and not found anything that works yet. >> >> Any suggestions? >> >> Thanks. >> >> Regards, >> Ozz. >> >> >> --------------------------------------------------------------------- >> Archive http://marc.info/?l=jaxlug-list&r=1&w=2 >> RSS Feed http://www.mail-archive.com/[email protected]/maillist.xml >> Unsubscribe [email protected] >> >> > --------------------------------------------------------------------- Archive http://marc.info/?l=jaxlug-list&r=1&w=2 RSS Feed http://www.mail-archive.com/[email protected]/maillist.xml Unsubscribe [email protected]

