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]