?
Solved

Removing spaces from output

Posted on 2003-03-27
2
Medium Priority
?
470 Views
Last Modified: 2012-06-21
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
Comment
Question by:DrewOZ
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Author Comment

by:DrewOZ
ID: 8220675
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
 

Accepted Solution

by:
tebeloin earned 140 total points
ID: 8302901
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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.
Suggested Courses
Course of the Month14 days, 13 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question