LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to remove extra spaces (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-remove-extra-spaces-4175492392/)

santosh0782 01-24-2014 05:54 AM

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 ?

druuna 01-24-2014 06:15 AM

Which spaces? The above example prints 0 if I execute it.

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

santosh0782 01-24-2014 06:46 AM

Quote:

Originally Posted by druuna (Post 5104293)
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

santosh0782 01-24-2014 06:48 AM

[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>


druuna 01-24-2014 06:58 AM

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.

santosh0782 01-24-2014 07:04 AM

Quote:

Originally Posted by druuna (Post 5104309)
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)

druuna 01-24-2014 07:15 AM

Quote:

Originally Posted by santosh0782 (Post 5104313)
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


santosh0782 01-24-2014 07:30 AM

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]

druuna 01-24-2014 07:40 AM

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.

schneidz 01-24-2014 12:05 PM

[quick-and-dirty]
Code:

awk -F ',' '/^[0-9]/{ print $5 }' opt4.txt | tr ' ' ''

druuna 01-24-2014 12:16 PM

Quote:

Originally Posted by schneidz (Post 5104495)
[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.

santosh0782 01-25-2014 11:32 PM

Quote:

Originally Posted by druuna (Post 5104506)
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 :-)

SAbhi 01-26-2014 01:23 AM

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.

santosh0782 01-26-2014 10:58 PM

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

santosh0782 01-27-2014 01:31 AM

As advised in post #12
Quote:

Originally Posted by druuna (Post 5104506)
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 :-)


All times are GMT -5. The time now is 07:20 AM.