[ksh, awk] determine values from rather complcated string


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [ksh, awk] determine values from rather complcated string
# 1  
Old 07-17-2009
[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  
Old 07-17-2009
Code:
nawk -F'[{=}|]' '{for(i=1;i<=NF;i++) if($i=="alarmId") print $(i+1)}' myFile

# 3  
Old 07-17-2009
@vgersh99,

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

E.J.
# 4  
Old 07-20-2009
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;

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Determine if first 2 digits of string match numbers

Trying to find out how to discover if the first 2 characters of a string are "22" Not sure how. I could use if ]; then echo "yes";fi But I think that will only grab the pattern 22 and not the first 2 digits. (5 Replies)
Discussion started by: newbie2010
5 Replies

2. UNIX for Dummies Questions & Answers

awk - How to join the string with values

Hi, I'm a beginner in awk script. I've been trying to figure how to concatenate two string in input file using awk after the value is calculated. I'm trying to get this format Apple 5.2(10) Orange 4.4(8) Watermelon 3.10(30) Berries 10.2(20) The input file with the format fruit... (2 Replies)
Discussion started by: KCApple
2 Replies

3. Shell Programming and Scripting

Using awk to determine if field value is valid

Hi Forum. I tried to search the forum posts for an answer but I haven't been able to do so for what I'm trying to accomplish. I have the following source file: 11936385~TFSA|11936385|4431|3401458067|10/09/1982|25.00|IBSBONUS|3200|||||CASH| 3401458067|1005|... (3 Replies)
Discussion started by: pchang
3 Replies

4. Shell Programming and Scripting

Determine the string is valid

Dear All, I have a string "1234567899*0#123456789#", it can be divided into: - 1st: 1234567899 Validation: 10 digits, only 0-9 - 2nd: *0# Fixed Value - 3rd: 123456789 Validation: 9 digits, only 0-9 - 4th: # Fixed Value Would like to know if any 1 line statement perl,... (5 Replies)
Discussion started by: jimmy_y
5 Replies

5. Shell Programming and Scripting

Using filename to determine a prefix that needs to be added to string column on file?

Possible filenames: CDD_Whatever.txt DDD_Whatever.txt If the file prefix = CDD, I'd like to prefix every person ID (second column in my examples below) on the file with "c-" If the file prefix = DDD, I'd like to prefix ever person ID with "d-" Input: Desired Output: Any help... (2 Replies)
Discussion started by: lrluis
2 Replies

6. Shell Programming and Scripting

awk + gsub to search multiple input values & replace with located string + extra text

Hi all. I have the following command that is successfully searching for any one of the strings on all lines of a file and replacing it with the instructed value. cat inputFile | awk '{gsub(/aaa|bbb|ccc|ddd/,"1234")}1' > outputFile This does in fact replace any occurrence of aaa, bbb,... (2 Replies)
Discussion started by: dazhoop
2 Replies

7. UNIX for Dummies Questions & Answers

Using awk/sed to determine whether there are any 2's, 3's and 4's in a column

Hi, I have a very large file which is of the general format: 0 3 4 2 ... 3 2 4 0 ... 0 3 4 2 ... 3 0 4 2 ... . . . . ... . . . . ... I would like to apply a simple awk/sed script to work out whether there are any 2's, 3's and 4's in each column. The results would look as... (3 Replies)
Discussion started by: kasan0
3 Replies

8. Shell Programming and Scripting

How to pick values from column based on key values by usin AWK

Dear Guyz:) I have 2 different input files like this. I would like to pick the values or letters from the inputfile2 based on inputfile1 keys (A,F,N,X,Z). I have done similar task by using awk but in that case the inputfiles are similar like in inputfile2 (all keys in 1st column and values in... (16 Replies)
Discussion started by: repinementer
16 Replies

9. Shell Programming and Scripting

Determine string in Perl.

Hi, I have a little Perl question. I need to determine the last word in the following string: h t t p://abc.def.com/hijklm The output should be the string hijklm. h t t p is of course http. The string between the slashes always differs. The string after the last slash always differs.... (4 Replies)
Discussion started by: ejdv
4 Replies

10. Shell Programming and Scripting

$A is a number / any other string? How to determine ?

I have a variable (say $A) and while passing it gets either a number or some other string. Now how can test (with if else) whether the variable is just a ne or something else ? Thanks a lot to all in advance C Saha (2 Replies)
Discussion started by: csaha
2 Replies
Login or Register to Ask a Question