Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Typecasting problem??

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 02-21-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 7 July 2015, 6:05 AM EDT
Location: Bangalore
Posts: 120
Thanks: 27
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 Unix and Linux 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 Unix and Linux 02-21-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 7 July 2015, 6:05 AM EDT
Location: Bangalore
Posts: 120
Thanks: 27
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 Unix and Linux 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 Unix and Linux 02-21-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 7 July 2015, 6:05 AM EDT
Location: Bangalore
Posts: 120
Thanks: 27
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 Unix and Linux 02-21-2013
RudiC RudiC is offline Forum Advisor  
Registered User
 
Join Date: Jul 2012
Last Activity: 1 August 2015, 4:33 AM EDT
Location: Aachen, Germany
Posts: 6,408
Thanks: 112
Thanked 1,770 Times in 1,656 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 Unix and Linux 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 . Linux
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 02:19 AM.