Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting


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

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-07-2013
Registered User
 
Join Date: Apr 2011
Location: Bangalore
Posts: 98
Thanks: 24
Thanked 2 Times in 2 Posts
Problems with one line output

my echo $var1 gives below value



Code:
Code:
1.7_NEW=25,1.7_RETAINED=30,1.7_RETURNING=40

i want it in 3 different values....

i.e. as



Code:
Code:
echo $1.7_NEW=25
echo $1.7_RETAINED=30
echo $1.7_RETURNING=40



the o/p of $1.7_NEW should be 25.....
Sponsored Links
    #2  
Old 01-07-2013
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,649
Thanks: 164
Thanked 642 Times in 619 Posts
You cannot assign variables named with numbers
i.e.;


Code:
a=somevalue
1.7_NEW=25  # this will generate an error.

So, could you show us what your input data looks like, so we can help you get output?
Sponsored Links
    #3  
Old 01-07-2013
Registered User
 
Join Date: Apr 2011
Location: Bangalore
Posts: 98
Thanks: 24
Thanked 2 Times in 2 Posts
hi jim

I did try the same.... but i did get error...
so i taut of asking help from this forum...

m getting this var1 value from DB with a simple select query....
    #4  
Old 01-07-2013
sathyaonnuix's Avatar
Registered User
 
Join Date: Aug 2012
Posts: 121
Thanks: 34
Thanked 13 Times in 12 Posts
Quote:
Originally Posted by nikhil jain View Post
the o/p of $1.7_NEW should be 25.....
What are you about to perform with these variables ?
Sponsored Links
    #5  
Old 01-07-2013
...@...
 
Join Date: Feb 2004
Location: NM
Posts: 9,649
Thanks: 164
Thanked 642 Times in 619 Posts

Code:
echo "$var1" |  awk -F[,=] '{print $2, $4, $6 } '

Start with that, and if you were to explain what you need rather than what you did, we could help more.
Sponsored Links
    #6  
Old 01-07-2013
Registered User
 
Join Date: May 2012
Posts: 6
Thanks: 3
Thanked 1 Time in 1 Post
Hi Nikhil,

I am assuming this this varibale is coming from a script, where you are trying to fetch data from a database. In case you ment to see the variables in different lines rather online We can use 'tr' command, hope this helps.


Code:
[Rob@mytestmachine~]# echo $var1|tr '[,]' '[\n]'
1.7_NEW=25
1.7_RETAINED=30
1.7_RETURNING=40

Sponsored Links
Reply

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
Converting line output to column based output npatwardhan Shell Programming and Scripting 8 03-24-2010 09:40 AM
My output Problems vinayrao Shell Programming and Scripting 1 02-12-2010 04:27 AM
problems getting a segment from a string output tzvio Shell Programming and Scripting 5 10-23-2009 06:06 AM
Help please...output problems with printf. pwanda UNIX for Advanced & Expert Users 3 10-19-2008 07:30 PM
how to make a line BLINKING in output and also how to increase font size in output mail2sant Shell Programming and Scripting 3 04-14-2008 07:30 AM



All times are GMT -4. The time now is 04:29 AM.