String parsing in Korn Shell


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting String parsing in Korn Shell
# 1  
Old 05-10-2010
Computer String parsing in Korn Shell

Hi everybody, I have a string stored in a variable called record:

record="SNMPv2-SMI::ent.9.9.43.1.3.9.2 = Timeticks: (177330898) 20 days, 12:35:08.98"

I want to write some regular expressions good for Korn Shell to extract the number between parenthesis, in this case 177330898, and put it in another variable called time.

Could somebody help me with this??SmilieSmilie
# 2  
Old 05-10-2010
Code:
variable=$( echo $record | sed  "s/.*(\([0-9]*\)).*/\1/" )

# 3  
Old 05-10-2010
Using ksh93 or bash or ...
Code:
a="${record%\)*}"    
num="${a##*\(}"

# 4  
Old 05-10-2010
thanks a lotSmilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Korn Shell manipulating the string into dynamic currency number

Conversion of string into currency value.. ex1: number_of_positions=2 input_string=345987 Output= 345,987.00 ex2: number_of_positions=4 input_string=1345987 Output= 1,345,987.0000 Please respond as soon as possible edit by bakunin: we will gladly respond as soon as... (15 Replies)
Discussion started by: suren.bills
15 Replies

2. Solaris

Korn shell - evaluating string gives wrong results due to limitations

Anyone ever seen this? Someone mentioned this the other day.... If you do, for instance, in korn shell, echo $(5.2+2.5), it gives the result of 6 regardless. Can't remember why but it was the limitation of the korn shell. (5 Replies)
Discussion started by: psychocandy
5 Replies

3. Shell Programming and Scripting

korn shell: check the content of a string of a variable

hello, i have a variable which should have following content : var="value1" or var="value2" or var="value2:*" # example: value2:22 how can i check : - if the content is ok (value1 / value2* ) - the two options of "value2" when content is example "value2:22" , i want to split... (3 Replies)
Discussion started by: bora99
3 Replies

4. Shell Programming and Scripting

Parsing a long string string problem for procmail

Hi everyone, I am working on fetchmail + procmail to filter mails and I am having problem with parsing a long line in the body of the email. Could anyone help me construct a reg exp for this string below. It needs to match exactly as this string. GetRyt... (4 Replies)
Discussion started by: cwiggler
4 Replies

5. UNIX for Dummies Questions & Answers

If statement for substring within string (korn)

Hi all, Just looking for a simple if statement that searches for a substring within a varaible, and then performs some function. Problem is that I need it to work in Korn shell $var = *string* does not work in Korn i="xxxxxx00.00yyyyy.zzzzz" want to find 00.00 (2 Replies)
Discussion started by: jgrosecl
2 Replies

6. Shell Programming and Scripting

Parsing the list in korn shell

Hi I wanted to print/store just a specific element of the list . I have got the list as an output of grep command. here is code snap below : end_no=`egrep -ni '!return code: 0|return code other than 0' temp.log | cut -d':' -f1` this will return the line numbers in end_no. I just... (2 Replies)
Discussion started by: Shell@korn
2 Replies

7. Shell Programming and Scripting

Parsing in korn shell

Hi Everyone, how do i parse following string from a file xyz.log in korn shell ? aa/bb{ CT{ GG{jjj/test} Thanks in advance, sweta (1 Reply)
Discussion started by: swetarati
1 Replies

8. Shell Programming and Scripting

Parsing of file for Report Generation (String parsing and splitting)

Hey guys, I have this file generated by me... i want to create some HTML output from it. The problem is that i am really confused about how do I go about reading the file. The file is in the following format: TID1 Name1 ATime=xx AResult=yyy AExpected=yyy BTime=xx BResult=yyy... (8 Replies)
Discussion started by: umar.shaikh
8 Replies

9. Shell Programming and Scripting

parsing a string in a shell script

I need to parse a string in a shell script. I understand there is some in built function to use that. can someone explain the syntax ? Say, it is like this #!/bin/ksh read input # input is entered as 'welcome' #Now I want to extract say only first 4 characters or last four #characters. ... (19 Replies)
Discussion started by: asutoshch
19 Replies

10. Shell Programming and Scripting

How to: Parse text string into variables using Korn shell

I am writing a script to keep check on free disk space, and I would like to find a way to parse $LINE (see code below) into a numeric value (for free disk space percentage) and a string value (for mount point). If possible, I would like to avoid sed or any additional use of awk since I am not very... (7 Replies)
Discussion started by: shew01
7 Replies
Login or Register to Ask a Question