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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Adding a columnfrom a specifit line number to a specific line number Ezy Shell Programming and Scripting 2 05-12-2008 05:29 AM
Appending line number to each line and getting total number of lines chiru_h Shell Programming and Scripting 2 03-25-2008 07:19 AM
Number count per number ranges shirleyeow Shell Programming and Scripting 5 12-19-2007 01:06 AM
to print number one less than actual number cdfd123 Shell Programming and Scripting 4 09-06-2007 03:56 AM
number pad in vi c19h28O2 SUN Solaris 5 09-20-2006 11:41 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 04-23-2008
Registered User
 

Join Date: May 2005
Posts: 192
a number situated just after = symbole

Hi,
I should read a number situated just after "= " symbole in a line from a file and put it in a variable.
the line in file is :
number of transaction=7

and I should put 7 in a variable (7 or other values), then
read the file :


And then how to select just the number after = symbole :

myvariable2=????

Thanks for help.
Reply With Quote
Forum Sponsor
  #2  
Old 04-23-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
If the text you want to analyze is in a variable already:

Code:
myvariable2=${othervar#*=}
This produces the value in othervar with anything up to the first equals sign removed.

If it's coming from a file which contains a single line:

Code:
myvariable2=`cut -d = -f2- otherfile`
There's a myriad different ways to split a file on a particular separator but cut is very simple and easy to understand. You could also do this with sed, awk, perl, or even grep (if you are a bit clever, and trust there to be exactly one equals sign in the file).

If there are multiple lines and you want the one with "number of transactions", try awk or sed:

Code:
myvariable2=`awk -F = '/number of transactions/ { print $2 }' otherfile`
Note that the backquote characters are "grave" ones (ASCII 96), not regular apostrophes.

Last edited by era; 04-23-2008 at 08:56 AM. Reason: awk example, too
Reply With Quote
  #3  
Old 04-23-2008
grial's Avatar
El UNIX es como un toro
 

Join Date: Jun 2006
Location: Madrid (Spain)
Posts: 531
hi big123456.
hint:
Code:
myvariable=$(echo "number of transaction=7" | cut -d= -f2)
Regards.

Last edited by grial; 04-23-2008 at 08:56 AM. Reason: era was faster!!! :)
Reply With Quote
  #4  
Old 04-23-2008
Registered User
 

Join Date: May 2005
Posts: 192
Thank to all.
era :
more otherfile
dfffffffffh fnjfjfjk ,kkkfkk
number of transaction=7
fffffffffffff fffg fhhfj k
mmf h ddddjj gggkjgk


My script (big.sh) :
myvariable2=`awk -F = '/number of transactions/ { print $2 }' otherfile'
echo $myvariable2

And now :

# ./big.sh
./big.sh: line 1: unexpected EOF while looking for matching ``'
./big.sh: line 3: syntax error: unexpected end of file


Thanks for help.
Reply With Quote
  #5  
Old 04-23-2008
era era is offline
Herder of Useless Cats
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,650
You seem to have replaced the final backquote with a regular apostrophe; it's probably better if you copy+paste the code from above in order to get the punctuation right.

Also, I carelessly put in "transactions" in plural; you will need to drop the final s. Sorry about that.
Reply With Quote
  #6  
Old 04-23-2008
Registered User
 

Join Date: May 2005
Posts: 192
It was that.
Many many thanks.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:19 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0