Problems with one line output | 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.

Problems with one line output

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 01-07-2013
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 24 June 2013, 8:52 AM EDT
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
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 19 April 2014, 8:15 AM EDT
Location: NM
Posts: 10,058
Thanks: 250
Thanked 756 Times in 711 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
nikhil jain nikhil jain is offline
Registered User
 
Join Date: Apr 2011
Last Activity: 24 June 2013, 8:52 AM EDT
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
sathyaonnuix sathyaonnuix is offline
Registered User
 
Join Date: Aug 2012
Last Activity: 4 December 2013, 2:33 AM EST
Posts: 127
Thanks: 34
Thanked 14 Times in 13 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
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 19 April 2014, 8:15 AM EDT
Location: NM
Posts: 10,058
Thanks: 250
Thanked 756 Times in 711 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
RobP RobP is offline
Registered User
 
Join Date: May 2012
Last Activity: 13 September 2013, 2:22 PM EDT
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
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
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 01:35 PM.