LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-24-2014, 05:54 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
how to remove extra spaces


Hi Friend,

I have a file:
cat opt4.txt



"OLDESTCALLWAITING"||','||"AVERAGESPEEDOFANSWER"||','||"CALLSWAITING"||','||"ACDCALLS"||','||"ABANDO NEDCALLS"
------------------------------------------------------------------------------------------------------------------------------------
0,0,0,2,0


i am taking the 5th field with this:
awk -F ',' '/^[0-9]/{ print $5 }' opt4.txt

it is giving the 5th field but along with it, it is giving the extra spaces, how could we get only 5th field without any spaces ?
 
Old 01-24-2014, 06:15 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Which spaces? The above example prints 0 if I execute it.

Put your example inside [code] ... [/code] tags it preserves all spacing.
 
Old 01-24-2014, 06:46 AM   #3
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
Which spaces? The above example prints 0 if I execute it.

Put your example inside [code] ... [/code] tags it preserves all spacing.


below is the complete code

Last edited by santosh0782; 01-24-2014 at 06:52 AM.
 
Old 01-24-2014, 06:48 AM   #4
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
[QUOTE=santosh0782;5104305]
Code:
#!/bin/ksh
#-----------------------------------------------------------------#
dataDir="/home/www/BCARD/data/rms/"
scriptDir="/home/111tora/rms/"
Pge_Update_dt="/home/www/BCARD/custom/CEMV/RMS/"
#-----------------------------------------------------------------#
. /wload/111t/app/oracle/oe/bin/oracle_login

for i in opt4 opt5 opt6
do
sqlplus CEMVOWNER/c3mv0wner#@TPCEMV @$i.sql
done

#-----------------------------------------------------------------#
opt4_AAD=$(awk -F ',' '/^[0-9]/ { print $1 }' ${scriptDir}/opt4.txt)            #MaxWaitTime (AverageAnswerDelay)
opt4_AAD_Time=$(awk -F ',' '/^[0-9]/{ h=$1/3600 ; m=($1%3600)/60 ; s=$1%60 ; printf("%02d:%02d:%02d\n", h, m, s) }' ${scriptDir}/opt4.txt)
                                                                                #MaxWaitTime(HH:MM:SS)(AverageAnswerDelay)
opt4_ASA=$(awk -F ',' '/^[0-9]/ { print $2 }' ${scriptDir}/opt4.txt)            #AverageAnswerDelay (AverageSpeedOfAnswer)
opt4_ASA_Time=$(awk -F ',' '/^[0-9]/{ h=$2/3600 ; m=($2%3600)/60 ; s=$2%60 ; printf("%02d:%02d:%02d\n", h, m, s) }' ${scriptDir}/opt4.txt)
                                                                                #AverageAnswerDelay(HH:MM:SS)(AverageSpeedOfAnswer)
opt4_Cwait=$(awk -F ',' '/^[0-9]/{ print $3 }' ${scriptDir}/opt4.txt)           #CallsWaiting (CallsWaiting)
opt4_ACD=$(awk -F ',' '/^[0-9]/{ print $4 }' ${scriptDir}/opt4.txt)             #CallsAnswered (ACDCalls)
opt4_Cabnd=$(awk -F ',' '/^[0-9]/{ print $5 }' ${scriptDir}/opt4.txt)           #CallsAbandoned (AbandonedCalls)

opt5_AAD=$(awk -F ',' '/^[0-9]/ { print $1 }' ${scriptDir}/opt5.txt)            #MaxWaitTime (AverageAnswerDelay)
opt5_AAD_Time=$(awk -F ',' '/^[0-9]/{ h=$1/3600 ; m=($1%3600)/60 ; s=$1%60 ; printf("%02d:%02d:%02d\n", h, m, s) }' ${scriptDir}/opt5.txt)
                                                                                #MaxWaitTime(HH:MM:SS)(AverageAnswerDelay)
opt5_ASA=$(awk -F ',' '/^[0-9]/ { print $2 }' ${scriptDir}/opt5.txt)            #AverageAnswerDelay (AverageSpeedOfAnswer)
opt5_ASA_Time=$(awk -F ',' '/^[0-9]/{ h=$2/3600 ; m=($2%3600)/60 ; s=$2%60 ; printf("%02d:%02d:%02d\n", h, m, s) }' ${scriptDir}/opt5.txt)
                                                                                #AverageAnswerDelay(HH:MM:SS)(AverageSpeedOfAnswer)
opt5_Cwait=$(awk -F ',' '/^[0-9]/ { print $3 }' ${scriptDir}/opt5.txt)          #CallsWaiting (CallsWaiting)
opt5_ACD=$(awk -F ',' '/^[0-9]/ { print $4 }' ${scriptDir}/opt5.txt)            #CallsAnswered (ACDCalls)
opt5_Cabnd=$(awk -F ',' '/^[0-9]/ { print $5 }' ${scriptDir}/opt5.txt)          #CallsAbandoned (AbandonedCalls)

opt6_AAD=$(awk -F ',' '/^[0-9]/ { print $1 }' ${scriptDir}/opt6.txt)            #MaxWaitTime (AverageAnswerDelay)
opt6_AAD_Time=$(awk -F ',' '/^[0-9]/{ h=$1/3600 ; m=($1%3600)/60 ; s=$1%60 ; printf("%02d:%02d:%02d\n", h, m, s) }' ${scriptDir}/opt6.txt)
                                                                                #MaxWaitTime(HH:MM:SS)(AverageAnswerDelay)
opt6_ASA=$(awk -F ',' '/^[0-9]/ { print $2 }' ${scriptDir}/opt6.txt)            #AverageAnswerDelay (AverageSpeedOfAnswer)
opt6_ASA_Time=$(awk -F ',' '/^[0-9]/{ h=$2/3600 ; m=($2%3600)/60 ; s=$2%60 ; printf("%02d:%02d:%02d\n", h, m, s) }' ${scriptDir}/opt6.txt)
                                                                                #AverageAnswerDelay(HH:MM:SS)(AverageSpeedOfAnswer)
opt6_Cwait=$(awk -F ',' '/^[0-9]/ { print $3 }' ${scriptDir}/opt6.txt)          #CallsWaiting (CallsWaiting)
opt6_ACD=$(awk -F ',' '/^[0-9]/ { print $4 }' ${scriptDir}/opt6.txt)            #CallsAnswered (ACDCalls)
opt6_Cabnd=$(awk -F ',' '/^[0-9]/ { print $5 }' ${scriptDir}/opt6.txt)          #CallsAbandoned (AbandonedCalls)
#-----------------------------------------------------------------#
#Defining Variables for lables and their values
#-----------------------------------------------------------------#

val[1]="${opt4_AAD}"
val[2]="${opt5_AAD}"
val[3]="${opt6_AAD}"
val[4]="${opt4_ASA}"
val[5]="${opt5_ASA}"
val[6]="${opt6_ASA}"

val_Time[1]="${opt4_AAD_Time}"
val_Time[2]="${opt5_AAD_Time}"
val_Time[3]="${opt6_AAD_Time}"
val_Time[4]="${opt4_ASA_Time}"
val_Time[5]="${opt5_ASA_Time}"
val_Time[6]="${opt6_ASA_Time}"

val[7]="${opt4_Cwait}"
val[8]="${opt5_Cwait}"
val[9]="${opt6_Cwait}"
val[10]="${opt4_ACD}"
val[11]="${opt5_ACD}"
val[12]="${opt6_ACD}"
val[13]="${opt4_Cabnd}"
val[14]="${opt5_Cabnd}"
val[15]="${opt6_Cabnd}"

lbl[1]='Opt 1 Sched : MaxWaitTime'
lbl[2]='Opt 2 Operations : MaxWaitTime'
lbl[3]='Option 3 : MaxWaitTime'
lbl[4]='Opt 1 Sched : AverageAnswerDelay'
lbl[5]='Opt 2 Operations : AverageAnswerDelay'
lbl[6]='Option 3 : AverageAnswerDelay'
lbl[7]='Opt 1 Sched : CallsWaiting'
lbl[8]='Opt 2 Operations : CallsWaiting'
lbl[9]='Option 3 : CallsWaiting'
lbl[10]='Opt 1 Sched : CallsAnswered'
lbl[11]='Opt 2 Operations : CallsAnswered'
lbl[12]='Option 3 : CallsAnswered'
lbl[13]='Opt 1 Sched : CallsAbandoned'
lbl[14]='Opt 2 Operations : CallsAbandoned'
lbl[15]='Option 3 : CallsAbandoned'

#-----------------------------------------------------------------#
#Drawing Pad
#-----------------------------------------------------------------#
#Reflecting data in 15 xmls for(MaxWaitTime/AverageAnswerDelay,AverageAnswerDelay/AverageSpeedOfAnswer,CallsWaiting,CallsAnswered/ACDCalls and CallsAbandoned/AbandonedCalls)
#-----------------------------------------------------------------#

for i in $(seq 1 1 15)
do
echo "<chart manageResize='1' bgAlpha='50' pallette='1' bgColor='FFFFFF' bgAlpha='45' bgRatio='50,45' bgAngle='90'>" >${dataDir}/dp_${i}a.xml
echo "<annotations scaleText='1'>" >>${dataDir}/dp_${i}a.xml
echo "        <annotationGroup id='Grp1'>" >>${dataDir}/dp_${i}a.xml
        if [[ $i -le 3 ]]
        then
                        if [[ "${val[$i]}" -lt 5 ]]
                        then
echo "        <annotation type='text' x='212.5' y='50' fontSize='85' bold='1' label='${val_Time[$i]}' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "        <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -ge 5 && "${val[$i]}" -le 10 ]]
                        then
echo "        <annotation type='text' x='212.5' y='50' fontSize='85' bold='1' label='${val_Time[$i]}' color='FF7E00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "        <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -ge 11 ]]
                        then
echo "        <annotation type='text' x='212.5' y='50' fontSize='85' bold='1' label='${val_Time[$i]}' color='FF0000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "        <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
                        fi
        fi

        if [[ $i -gt 3 && $i -le 6 ]]
        then
                        if [[ "${val[$i]}" -le 30 ]]
                        then
echo "        <annotation type='text' x='212.5' y='50' fontSize='85' bold='1' label='${val_Time[$i]}' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "        <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -gt 30 && "${val[$i]}" -le 60 ]]
                        then
echo "        <annotation type='text' x='212.5' y='50' fontSize='85' bold='1' label='${val_Time[$i]}' color='FF7E00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "        <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -gt 60 ]]
                        then
echo "        <annotation type='text' x='212.5' y='50' fontSize='85' bold='1' label='${val_Time[$i]}' color='FF0000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "        <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
                        fi
        fi

        if [[ $i -gt 6 && $i -le 9 ]]
        then
                        if [[ "${val[$i]}" -lt 1 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -ge 1 && "${val[$i]}" -le 5 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='FF7E00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -gt 5 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='FF0000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        fi
        fi

        if [[ $i -gt 9 && $i -le 12 ]]
        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

        fi

        if [[ $i -gt 12 && $i -le 15 ]]
        then
                        if [[ "${val[$i]}" -lt 10 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -ge 10 && "${val[$i]}" -le 20 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='FF7E00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -gt 20 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='FF0000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        fi
        fi

echo "        </annotationGroup>" >>${dataDir}/dp_${i}a.xml
echo "</annotations>" >>${dataDir}/dp_${i}a.xml
echo "<styles>" >>${dataDir}/dp_${i}a.xml
echo "        <definition>" >>${dataDir}/dp_${i}a.xml
echo "                <style name='myBevel' type='Bevel' />" >>${dataDir}/dp_${i}a.xml
echo "        </definition>" >>${dataDir}/dp_${i}a.xml
echo "        <application>" >>${dataDir}/dp_${i}a.xml
echo "                <apply toObject='Background' styles='myBevel' />" >>${dataDir}/dp_${i}a.xml
echo "        </application>" >>${dataDir}/dp_${i}a.xml
echo "</styles>" >>${dataDir}/dp_${i}a.xml
echo "</chart>" >>${dataDir}/dp_${i}a.xml

done

#-----------------------------------------------------------------#
#To Populate Today's date and Time
#-----------------------------------------------------------------#
last_date=$(date)
echo "<?xml version=\"1.0\"?>">${Pge_Update_dt}/LastUpdatedDate.xml
echo "<root>">>${Pge_Update_dt}/LastUpdatedDate.xml
echo "<date>">>${Pge_Update_dt}/LastUpdatedDate.xml
echo "<LastUpdatedDt>$last_date</LastUpdatedDt>">>${Pge_Update_dt}/LastUpdatedDate.xml
echo "</date>">>${Pge_Update_dt}/LastUpdatedDate.xml
echo "</root>">>${Pge_Update_dt}/LastUpdatedDate.xml
#-----------------------------------------------------------------#

from the above code below piece of code is giving spaces in output xmls:
Code:
if [[ $i -gt 12 && $i -le 15 ]]
        then
                        if [[ "${val[$i]}" -lt 10 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -ge 10 && "${val[$i]}" -le 20 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='FF7E00' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        elif [[ "${val[$i]}" -gt 20 ]]
                        then
echo "       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='${val[$i]}' color='FF0000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml
echo "       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='${lbl[$i]}' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />" >>${dataDir}/dp_${i}a.xml

                        fi
        fi
there are 15 xmls , out of which 13th, 14th and 15th xml is having spaces as(here i am giving it for 13th xml only, same issue is with 14th and 15th):
cat dp_13a.xml
Code:
<chart manageResize='1' bgAlpha='50' pallette='1' bgColor='FFFFFF' bgAlpha='45' bgRatio='50,45' bgAngle='90'>
<annotations scaleText='1'>
        <annotationGroup id='Grp1'>
       <annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='0                                                                                                                         ' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />(after label='0    lot of space is coming in output and due to whcih it is not displaying on dashboard)
       <annotation type='text' x='212.5' y='110' fontSize='18' bold='1' label='Opt 1 Sched : CallsAbandoned' color='000000' align='center' font='tohama,helvetica,arial,sans-serif' />
        </annotationGroup>
</annotations>
<styles>
        <definition>
                <style name='myBevel' type='Bevel' />
        </definition>
        <application>
                <apply toObject='Background' styles='myBevel' />
        </application>
</styles>
</chart>

Last edited by santosh0782; 01-24-2014 at 06:54 AM.
 
Old 01-24-2014, 06:58 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
I don't see what your original question has in common with the dumps you posted in posts #3 and #4......

It also doesn't show which (extra) spaces you are talking about.
 
Old 01-24-2014, 07:04 AM   #6
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
I don't see what your original question has in common with the dumps you posted in posts #3 and #4......

It also doesn't show which (extra) spaces you are talking about.
the above code generating below xml, where it has lot of space after label
cat dp_13a.xml
Code:
<annotation type='text' x='212.5' y='50' fontSize='100' bold='1' label='0                                                                                                                        ' color='00FF00' align='center' font='tohama,helvetica,arial,sans-serif' />
(after label='0    lot of space is coming in output and due to whcih it is not displaying on dashboard)
and this command puts that label value:
opt4_Cabnd=$(awk -F ',' '/^[0-9]/{ print $5 }' ${scriptDir}/opt4.txt) #CallsAbandoned (AbandonedCalls)

Last edited by santosh0782; 01-24-2014 at 07:06 AM.
 
Old 01-24-2014, 07:15 AM   #7
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by santosh0782 View Post
and this command puts that label value:
Code:
opt4_Cabnd=$(awk -F ',' '/^[0-9]/{ print $5 }' ${scriptDir}/opt4.txt)           #CallsAbandoned (AbandonedCalls)
The awk command shown doesn't produce any extra spaces when using the example from post #1.

I can only assume that the input file (opt4.txt) does not look like the example shown.
Code:
$ cat santosh0782.in 




"OLDESTCALLWAITING"||','||"AVERAGESPEEDOFANSWER"||','||"CALLSWAITING"||','||"ACDCALLS"||','||"ABANDO NEDCALLS"
------------------------------------------------------------------------------------------------------------------------------------
0,0,0,2,0
$ awk -F',' '/^[0-9]/{ print $5 }' santosh0782.in 
0
$ awk -F',' '/^[0-9]/{ print "X" $5 "X" }' santosh0782.in 
X0X

Last edited by druuna; 01-25-2014 at 05:48 AM. Reason: fixed a typo
 
Old 01-24-2014, 07:30 AM   #8
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
this sql script generates that file:
spool opt4.txt
select "OldestCallWaiting"||','||"AverageSpeedOfAnswer"||','||"CallsWaiting"||','||"ACDCalls"||','||"Abando nedCalls" from dbo.vwAvayaCMSRealTimeSplitSummary@dg4
where "Split" in ('857');
spool off;
quit;


when i open this opt4.txt in vim and goes for the last character it goes:

"OLDESTCALLWAITING"||','||"AVERAGESPEEDOFANSWER"||','||"CALLSWAITING"||','||"ACDCALLS"||','||"ABANDO NEDCALLS"
------------------------------------------------------------------------------------------------------------------------------------
71,101,1,1,1 after lot of space [cursor goes here]
 
Old 01-24-2014, 07:40 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
So, my assumption was correct.

The awk command works as designed. You set the delimiter to , and print field number 5. Field number 5 start right after the , and all after it is part of that field (which would include the spaces).

The best solution would be to create a consistent output file (the extra spaces shouldn't be there), that way you don't have to deal with inconsistent data when you parse it in a (shell) script.
 
2 members found this post helpful.
Old 01-24-2014, 12:05 PM   #10
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,028

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
[quick-and-dirty]
Code:
awk -F ',' '/^[0-9]/{ print $5 }' opt4.txt | tr ' ' ''
 
Old 01-24-2014, 12:16 PM   #11
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387Reputation: 2387
Quote:
Originally Posted by schneidz View Post
[quick-and-dirty]
Code:
awk -F ',' '/^[0-9]/{ print $5 }' opt4.txt | tr ' ' ''
Using a multi-delimiter would be simpler:
Code:
awk -F'[ ,]' '/^[0-9]/{ print $5 }
But like I said before; Working with an input file that isn't consistent isn't recommended and it can give you (and your possible successor) an "interesting" time troubleshooting the problems that might arise.
 
1 members found this post helpful.
Old 01-25-2014, 11:32 PM   #12
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by druuna View Post
Using a multi-delimiter would be simpler:
Code:
awk -F'[ ,]' '/^[0-9]/{ print $5 }
But like I said before; Working with an input file that isn't consistent isn't recommended and it can give you (and your possible successor) an "interesting" time troubleshooting the problems that might arise.
ok, Let me try this command, and will let you know the status. also i'll try to find out how we can fetch the required fields from a SQL table without any extra spaces, so that this problem will not occur.
Thanks a Lot Friend :-)
 
Old 01-26-2014, 01:23 AM   #13
SAbhi
Member
 
Registered: Aug 2009
Location: Bangaluru, India
Distribution: CentOS 6.5, SuSE SLED/ SLES 10.2 SP2 /11.2, Fedora 11/16
Posts: 664

Rep: Reputation: 80
hmmm well this could be of some help for you:
Code:
SELECT col1,col2,col3
FROM table_name
INTO OUTFILE '/tmp/tempfile.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
i know sql output from terminal usually go wierd when redirected to a text file. A csv may help to sort it out and can be used in your script as if a regular text file.
 
Old 01-26-2014, 10:58 PM   #14
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
i tried this way:
Code:
TPCEMV CEMVOWNER SQL> SELECT "AverageAnswerDelay","AverageSpeedOfAnswer","CallsWaiting","ACDCalls","AbandonedCalls" FROM dbo.vwAvayaCMSRealTimeSplitSummary@dg4 where "Split" in ('857')  INTO OUTFILE 'opt9.txt' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' ;
SELECT "AverageAnswerDelay","AverageSpeedOfAnswer","CallsWaiting","ACDCalls","AbandonedCalls" FROM dbo.vwAvayaCMSRealTimeSplitSummary@dg4 where "Split" in ('857') INTO OUTFILE 'opt9.txt' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
*
ERROR at line 1:
ORA-00933: SQL command not properly ended


Code:
TPCEMV CEMVOWNER SQL> select "OldestCallWaiting"||','||"AverageSpeedOfAnswer"||','||"CallsWaiting"||','||"ACDCalls"||','||"AbandonedCalls" FROM dbo.vwAvayaCMSRealTimeSplitSummary@dg4 where "Split" in ('857')  INTO OUTFILE 'opt9.txt' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' ;
select "OldestCallWaiting"||','||"AverageSpeedOfAnswer"||','||"CallsWaiting"||','||"ACDCalls"||','||"Abando nedCalls" FROM dbo.vwAvayaCMSRealTimeSplitSummary@dg4 where "Split" in ('857') INTO OUTFILE 'opt9.txt' FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n'
*
ERROR at line 1:
ORA-00933: SQL command not properly ended

Last edited by santosh0782; 01-26-2014 at 11:38 PM.
 
Old 01-27-2014, 01:31 AM   #15
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
As advised in post #12
Quote:
Originally Posted by druuna View Post
Using a multi-delimiter would be simpler:
Code:
awk -F'[ ,]' '/^[0-9]/{ print $5 }
But like I said before; Working with an input file that isn't consistent isn't recommended and it can give you (and your possible successor) an "interesting" time troubleshooting the problems that might arise.
as i need first five fields from the table, i am selecting one more field from table and then fetching the details for 5 fields amongst 6 and its working fine now.

but i'll search how to remove spaces only with selected fields in SQL.

Thanks a lot Friend :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing extra unwanted spaces anshaa Linux - Newbie 2 08-22-2012 10:34 AM
[SOLVED] awk print $0 delete extra spaces problem fantasy1215 Programming 4 07-09-2012 04:42 AM
[SOLVED] ubuntu : delete the extra spaces Xanios Linux - Newbie 13 07-29-2010 12:15 AM
[SOLVED] Remove extra spaces in a line vikas027 Programming 11 10-11-2008 09:20 AM
Html: Extra Spaces on Top mikeshn Programming 1 07-05-2003 04:40 PM


All times are GMT -5. The time now is 12:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration