Segregate a number from a String in the log


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Segregate a number from a String in the log
# 1  
Old 12-18-2012
Segregate a number from a String in the log

Hi,

I have below lines in the log file. how to segregate and assign '3904' to a variable.

Code:
XCMM018I  Return Code: 8  Feedback: 0
          :&PNUM=3904:


Last edited by jim mcnamara; 12-18-2012 at 12:56 PM.. Reason: code tags
# 2  
Old 12-18-2012
Code:
$ awk '/NUM/{gsub("[A-Za-z:&=]","");print}' input.txt
3904

# 3  
Old 12-18-2012
You could try the clumsy cut:-
Code:
string=":&PNUM=3904:"
my_var="`echo $string | cut -f2 -d= | cut -f1 -d:`"

... or if you have ksh installed, you could:-

Code:
#!/bin/ksh
string=":&PNUM=3904:"
my_temp_var="${string#*=}"
my_var="${string%:}"

You could also use tr to get rid of non-numerics like this:-
Code:
string=":&PNUM=3904:"
my_var="`echo $string | tr -d [a-zA-Z&=:]`"


I hope that these help, and you may get other suggestions.



Robin
Liverpool/Blackburn
UK
# 4  
Old 12-18-2012
To assign 3904 to a variable, use the following:
Code:
variable=3904

If you want to recognize 3904 in your log file and also recognize other values in your log file, you need to give us more information about how to determine what value(s) you want and how to recognize them.

Are you looking for any string of 4 digits that does not immediately follow an alphabetic character?

Are you looking for any string of digits following an equal sign character?

Are you looking for a number following &PNUM=?

If there is more than one string of digits that meets your criteria, do you want the first one, the last one, all of them, etc.?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script if ( $0 ~ /SVC IN:/ ) { svc_in=substr( $0,23 , 3); if (msg_start == 1 && msg_end == 0) { msg_arr=$0; } } else if ( $0 ~ /^SVC OUT:/ ) { svc_out=substr( $0, 9, 3); if (msg_start == 1 && msg_end == 0) ... (6 Replies)
Discussion started by: bhagya123
6 Replies

2. Shell Programming and Scripting

How to segregate a section from big file?

Hello, I need to know all IP range (ip_prefix), associated with us-west-2 region only from this link - https://ip-ranges.amazonaws.com/ip-ranges.json (it can be opened in wordpad for better visibility) Please suggest, how would I do it. If vi, awk or sed is needed, I have downloaded it on my... (7 Replies)
Discussion started by: solaris_1977
7 Replies

3. Shell Programming and Scripting

Segregate files based on the time they are created

Hi All, I have scenario where I need to zip huge number of DB audit log files newer than 90 days and delete anything older than that. If the files are too huge in number,zipping will take long time and causing CPU spikes. To avoid this I wanted to segregate files based on how old they are and... (2 Replies)
Discussion started by: veeresh_15
2 Replies

4. UNIX for Advanced & Expert Users

Segregate file content using sed backreference

I have some text like EU1BTDAT:ASSGNDD filename='$SEQFILES/SUNIA.PJ008202.CARDLIB/DATECARD' EU1BTDATEST:ASSGNDD filename='$SEQFILES/SUNIA.PJ008202.CARDLIB/DATECARD' EU1CLOSEDATES:ASSGNDD filename='$SEQFILES/SUNIA.PJ008202.CARDLIB/DATECARD' EU1DATED:ASSGNDD... (8 Replies)
Discussion started by: gotamp
8 Replies

5. Shell Programming and Scripting

Segregate by suffixed file names using Korn Shell

I have following files at /dir1 a.csv.20131201 b.csv.20131201 c.csv.20131201 d.csv.20131201 a.csv.20131202 b.csv.20131202 c.csv.20131202 d.csv.20131202 ....................... ....................... ....................... ....................... I need to move these files to... (4 Replies)
Discussion started by: JaisonJ
4 Replies

6. Shell Programming and Scripting

Segregate alpha and digits

I have a variable containing values like 10d2, 7a7, a8 or d6 (i.e. <digits><alpha><digits>. Out of these leading digits may not be there. Out of this, I want three variables. The first having value Inital digits, the second one will be alpha and the third will be trailing digits. (In the previous... (2 Replies)
Discussion started by: Soham
2 Replies

7. Shell Programming and Scripting

How can i segregate?

I have this file which contains 91886,000,MiniC2-00,1.9.12,aML,en 91886,000,MiniC2-00,1.9.12,aML,en 91886,000,MiniC2-00,1.9.12,aML,en 91886,000,MiniC2-00,1.9.12,aML,en 91886,000,MiniC2-00,1.9.12,aML,en 91886,000,MiniC2-00,1.9.12,aML,en 91886,000,MiniC2-00,3.0,aML,en... (6 Replies)
Discussion started by: nikhil jain
6 Replies

8. Shell Programming and Scripting

How to string with most number of accurances in log file

Dear Friends, I am new to this forum and this is my first thread. How to find the maximum number of occurrences in a log file. A log file contains the list of the ip addresses that makes get request to the server. The script has to find the ip which makes maximum number of requests to the server... (3 Replies)
Discussion started by: tamil.pamaran
3 Replies

9. Shell Programming and Scripting

changing number in bash (number is in form of string)

I have a txt file as database. when i run my program what it does is it ask me for 3 name and stored in the file as name1:name2:name3:1 when u enter 3 name it add those in file as above format and add 1 at the end. I what i want is if i enter same names again it changes that 1 to 2 and so... (3 Replies)
Discussion started by: Learnerabc
3 Replies

10. Shell Programming and Scripting

segregate the file based on matching patterns

print 'test' SETUSER 'dbo' go create proc abc as /Some code here/ go SETUSER go print 'test1' SETUSER 'dbo' go Create Procedure xyz as /some code here/ go SETUSER go print 'test2' SETUSER 'dbo' (2 Replies)
Discussion started by: mad_man12
2 Replies
Login or Register to Ask a Question