The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need help to seperate data getdpg Shell Programming and Scripting 4 08-30-2006 06:28 AM
extract from string variable into new variables Sniper Pixie UNIX for Dummies Questions & Answers 2 03-03-2006 10:49 AM
Cut a Variable into sub variables based on a delimiter jingi1234 UNIX for Dummies Questions & Answers 6 05-06-2005 11:41 AM
/usr/lib on a seperate partition progressdll UNIX for Advanced & Expert Users 4 12-21-2004 09:59 AM
row seperate inquirer Shell Programming and Scripting 13 08-12-2003 06:26 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rating: Thread Rating: 2 votes, 4.00 average. Display Modes
  #1 (permalink)  
Old 08-03-2008
intikhabalam intikhabalam is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 3
how to seperate a variable in 2 variables

Dear all,

i dont know how to split one variable value in 2 variable. please send me any example.

variable1= "abcde developer"

now i want to seperate the values and seperator is space.
  #2 (permalink)  
Old 08-03-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,813

Code:
var1="abcde developer"
echo "$var1" | read var2 var3
echo "$var2"
echo "$var3"

  #3 (permalink)  
Old 08-03-2008
intikhabalam intikhabalam is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 3
thanks alot for your quick response, but it is including ^M at the end and also entering a blank line.

plz have a look

for myvar1 in $(awk -F, '{print $1,$5}' $Filename $filen|tr "a-z" "A-Z" )
do
echo "$myvar1" | read var2 var3
sqlplus -s test/test@test @gur.sql $DefaultProduct $var2 $var3
done >>getdata.tmp

in above example, i have to give 3 parameters to gur.sql, i am reading a variable myvar1 from a file, this variable contains 2 values of $1,$5. now i am using your command but its not working. plz if possible then answer it ASAP.

thanks alot
  #4 (permalink)  
Old 08-03-2008
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,433
Quote:
thanks alot for your quick response, but it is including ^M at the end and also entering a blank line.
If you get ^M and/or empty lines, the problem commes from your input datas and not from the read command.
You can modify your awk command to remove ¨M and empty lines :

Code:
for myvar1 in $(awk -F, 'NF {gsub(/\r/, ""); print $1,$5}' $Filename |tr "a-z" "A-Z" )

Another way :

Code:
awk -F, 'NF {gsub(/\r/, ""); print tolower($1),tolower($5)}' $Filename | \
while read var2 var3
do
   sqlplus -s test/test@test @gur.sql $DefaultProduct $var2 $var3
done >>getdata.tmp

Jean-Pierre.
  #5 (permalink)  
Old 08-03-2008
ghostdog74 ghostdog74 is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2006
Posts: 2,560

Code:
read var2 var3 <<<$var1

  #6 (permalink)  
Old 08-03-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
And don't forget the ever venerable


Code:
set -- $var1  # populate $* from $var1, split on $IFS
var2=$1
var3=$2

  #7 (permalink)  
Old 08-04-2008
intikhabalam intikhabalam is offline
Registered User
  
 

Join Date: Aug 2008
Posts: 3
Thanks alot brothers,
i have done with your help.


Regards,
Intikhab Alam
Certified ISMS 27001 Lead Auditor (Information Security Management System)
Certified ISO 9000:2000 Lead Auditor
Brainbench SCM, SQA, Testing & SEI CMMI Certified
CMA-CGM SYSTeMS

(A Joint Venture of CMA-CGM and IBM)
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:24 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0