![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
If the text you want to analyze is in a variable already:
Code:
myvariable2=${othervar#*=}
If it's coming from a file which contains a single line: Code:
myvariable2=`cut -d = -f2- otherfile` 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`
Last edited by era; 04-23-2008 at 08:56 AM. Reason: awk example, too |
|
#3
|
||||
|
||||
|
hi big123456.
hint: Code:
myvariable=$(echo "number of transaction=7" | cut -d= -f2) Last edited by grial; 04-23-2008 at 08:56 AM. Reason: era was faster!!! :) |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
It was that.
Many many thanks. |
|||
| Google The UNIX and Linux Forums |