Typecasting problem?? | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Typecasting problem??

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 02-21-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 11 August 2014, 3:10 AM EDT
Location: Bangalore
Posts: 114
Thanks: 25
Thanked 2 Times in 2 Posts
Typecasting problem??


Code:
Code:
 echo $verbiage
"Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"


but when i run this command


Code:
Code:
sed 's/$/",$verbiage"/g' noverb.F5


I get below o/p


Code:
Code:
",$verbiage"0,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN
",$verbiage"4,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN
",$verbiage"2,pSSDGuUiPRX5c2MQUaBKYjvzOwg=,S30,4.0,MTN


file content is


Code:
Code:
23470330,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN
2398774,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN
2379162,pSSDGuUiPRX5c2MQUaBKYjvzOwg=,S30,4.0,MTN

required o/p is


Code:
Code:
23484374,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN,"Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"
23480162,pSSDGuUiPRX5c2MQUaBKYjvzOwg=,S30,4.0,MTN,"Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"

Sponsored Links
    #2  
Old 02-21-2013
Vikram_Tanwar12 Vikram_Tanwar12 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 21 November 2013, 3:32 AM EST
Posts: 168
Thanks: 13
Thanked 10 Times in 10 Posts
Try this


Code:
sed -i "s/\$/ ,$verbiage/" noverb.F5

Sponsored Links
    #3  
Old 02-21-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 11 August 2014, 3:10 AM EDT
Location: Bangalore
Posts: 114
Thanks: 25
Thanked 2 Times in 2 Posts
Hi vikram

I tried ur command, but it aint working, its just givin me the o/p of verbiage


Code:
Code:
 , "Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"
 , "Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"
 , "Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"

    #4  
Old 02-21-2013
Vikram_Tanwar12 Vikram_Tanwar12 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 21 November 2013, 3:32 AM EST
Posts: 168
Thanks: 13
Thanked 10 Times in 10 Posts

Code:
cat vikram13.sh
23470330,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN
2398774,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN
2379162,pSSDGuUiPRX5c2MQUaBKYjvzOwg=,S30,4.0,MTN


Code:
vi vikram14.sh
#!/bin/sh
verbiage=('"Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"')
echo $verbiage
sed -i "s/\$/, $verbiage/" vikram13.sh

After running the script
Code:
vikram14.sh


Code:
cat vikram13.sh
23470330,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN, "Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"
2398774,s2ZsUMmoMCdllhIdZSWxdBl7cH0=,S40,1.6.52,MTN, "Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"
2379162,pSSDGuUiPRX5c2MQUaBKYjvzOwg=,S30,4.0,MTN, "Nigeria","Can Nigeria succeed in their quest for a top 4 finish? Get daily Nigeria news, GOALS and LIVE Match updates for 30days at N200.Click Accept to SUBSCRIBE"

Sponsored Links
    #5  
Old 02-21-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 11 August 2014, 3:10 AM EDT
Location: Bangalore
Posts: 114
Thanks: 25
Thanked 2 Times in 2 Posts
Vikram

when i'm running inside the script m gettin the same o/p as mentiond previously


Code:
Code:
while read line
do
batch=`echo $line|awk -F"|" '{print $1}'`
echo "$line"|awk -F"|" '{print $2}'>verbiage_file.$batch
grep $batch icm_sample.csv > toberun.csv.$batch
sed "s/:/,/g" verbiage_file.$batch>org_verbiage.$batch
verbiage=`cat org_verbiage.$batch`
#awk -F"," '{print $2","$3","$4","$5","$6}' toberun.csv.$batch > noverb.$batch
#sed "s/$/,$verbiage/g" noverb.$batch > actual.$batch
sed -i "s/\$/, $verbiage/" toberun.csv.$batch
#paste actual.$batch org_verbiage.$batch > file_running.$batch
done < test
~

Sponsored Links
    #6  
Old 02-21-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 30 August 2014, 4:29 AM EDT
Location: Aachen, Germany
Posts: 4,141
Thanks: 67
Thanked 986 Times in 934 Posts
I'd bet your file has windows control chars in it, at least a <CR> at the end. Get rid of those and it will fly.
And, in the regex, you don't need the \ in front of the $ sign representing the line end...
The Following User Says Thank You to RudiC For This Useful Post:
nikhil jain (02-21-2013)
Sponsored Links
    #7  
Old 02-21-2013
Vikram_Tanwar12 Vikram_Tanwar12 is offline
Registered User
 
Join Date: Nov 2012
Last Activity: 21 November 2013, 3:32 AM EST
Posts: 168
Thanks: 13
Thanked 10 Times in 10 Posts
Hello Rudic,

Thanks for correcting me.
Code:
\

not required in front of
Code:
$

in regex .
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
C Programming.. Typecasting of structure pointers.. Priya Amaresh Programming 3 08-31-2012 04:32 AM
Problem with forwarding emails (SPF problem) carwe IP Networking 0 08-16-2011 06:17 AM
user login problem & Files listing problem. pernasivam AIX 1 06-18-2009 09:09 AM
ssh script problem problem pcjandyala Shell Programming and Scripting 2 07-31-2008 03:27 PM
problem with dd command or maybe AFS problem Anta Shell Programming and Scripting 0 08-25-2006 10:10 AM



All times are GMT -4. The time now is 08:14 AM.