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 and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Append values before a string Nandagopal Shell Programming and Scripting 2 04-11-2009 07:04 AM
How to delete ctrl key values in a given string? balan_mca Shell Programming and Scripting 4 10-16-2008 12:03 PM
to separate values from a string ssuresh1999 UNIX for Dummies Questions & Answers 3 10-07-2008 01:23 PM
Determine string in Perl. ejdv Shell Programming and Scripting 4 05-14-2008 05:34 AM
$A is a number / any other string? How to determine ? csaha Shell Programming and Scripting 2 02-21-2006 04:03 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-17-2009
ejdv ejdv is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 46
[ksh, awk] determine values from rather complcated string

Hi there,

I tried and tried, but cannot solve this myself.

I have this string:


Code:
enterprises.alcatel.nmu.genos.alarmHandoff.alarmHandoffPurge.purgelistAlarmIds.0 = {alarmId=63868|friendlyName=Dortmund/r01sr1sl01/port#06-#01-Vc12|probableCause=Server Signal Failure},{alarmId=63924|friendlyName=Dortmund/r01sr1sl01/port#06-P|probableCause=Loss Of Signal}

I need to have the alarmId values "63868" and "63924" extracted from it.
The alarmId values are variable of course.
And it can be that 1 to endless amount of alarmIds are present.
So, in this example there are 2, but it can be 1 and it can be 50.

I need to use it in a ksh script.

Any ideas ?

Thanks in advance,

E.J.
  #2 (permalink)  
Old 07-17-2009
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,131

Code:
nawk -F'[{=}|]' '{for(i=1;i<=NF;i++) if($i=="alarmId") print $(i+1)}' myFile

  #3 (permalink)  
Old 07-17-2009
ejdv ejdv is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 46
@vgersh99,

Thanks a lot !!!
Works perfect.
But you already knew that :-)

E.J.
  #4 (permalink)  
Old 07-20-2009
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,099

Code:
$str='enterprises.alcatel.nmu.genos.alarmHandoff.alarmHandoffPurge.purgelistAlarmIds.0 = {alarmId=63868|friendlyName=Dortmund/r01sr1sl01/port#06-#01-Vc12|probableCause=Server Signal Failure},{alarmId=63924|friendlyName=Dortmund/r01sr1sl01/port#06-P|probableCause=Loss Of Signal}I need to have the alarmId values "63868" and "63924" extracted from it.';
@tmp=$str=~/alarmId=([0-9]+)/g;
print join "\n", @tmp;

Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 07:23 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0