• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 478
  • Last Modified:

Removing spaces from output

Hey All,

I've got a unix script that is checking whether the current date is more than 2 days difference to the date in a database. I know exactly what the issue is, but I can't figure a solution. Firstly, here's the script:

sqlplus -s generalapps/******@auam33pd >escalateoutput.sh <<SQL_END
set head off
set feedback off
set pages 0
set lines 500

SELECT
     'if (( ' || (sysdate - wl.opp_date) || ' > 2 )) ; then' || chr(13) || chr(10) ||
        'mailx -s ' || chr(39) || 'Win/Loss Report' || chr(39) ||
        ' drewwalkeris@alwaysonline.net.au <<MSGEND' || chr(13) || chr(10) ||
        'Test ' ||
        chr(13) || chr(10) || 'MSGEND' || chr(13) || chr(10) ||
     'fi;'
FROM
     mde_user.opportunity opp, mde_user.ad_user adusr, mde_user.employee emp, generalapps.win_loss wl
WHERE
        (opp.dek_opportunity = wl.dek_opportunity AND wl.report_status = 'Initiated')
        AND (opp.dek_ad_user = adusr.dek_ad_user
        AND adusr.dek_employee = emp.dek_employee);

SQL_END

chmod 777 escalateoutput.sh
ksh escalateoutput.sh

Here's a sample of what the output is like:

if (( .740497685185185185185185185185185185185 > 2 )) ; then                    
mailx -s 'Win/Loss Report' WalkeD2@AUSTRALIA.Stortek.com <<MSGEND              
Test                                                                            
MSGEND                                                                          
fi;                                                                            

The problem is that the output is actually this (The *'s indicate spaces):

if (( .740497685185185185185185185185185185185 > 2 )) ; then********************
mailx -s 'Win/Loss Report' WalkeD2@AUSTRALIA.Stortek.com <<MSGEND***************
Hi******************************************************************************
MSGEND**************************************************************************
fi;*****************************************************************************

If I remove the spaces from the outputfile and then execute it, it works fine. If I leave the spaces, I get "'fi' unexpected". Is there a way to get around this?

I've been testing with copying and pasting the code directly into korn shell, and it seems the only way to get around it is by getting rid of those spaces some how.

Many Thanks,
Drew
0
DrewOZ
Asked:
DrewOZ
1 Solution
 
DrewOZAuthor Commented:
Hey, sorry guys, I realised I made a stupid mistake, I can just include "sysdate - wl.opp_date > 2" into the WHERE clause and remove the "if" statement. This question can be deleted or left so that people don't make the same stupid mistake. :)

Drew
0
 
tebeloinCommented:
Well, I'm already here, so I thought I'd pass along a solution, in case you need something like this again.  You can use sed to strip out occurrences of more than one blank space, as in:

sed -e "s/  *//g" < testfile.sh > strippedfile.sh

Note that there are TWO blank spaces before the asterisk in this commnand.  We are finding two more more blank spaces in file testfile.sh and replacing them with nothing, then outputting it to a new file called strippedfile.sh.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now