Sponsored Content
Top Forums Shell Programming and Scripting Regex in sed to find specific pattern and assign to variable Post 302881581 by radioactive9 on Monday 30th of December 2013 10:53:02 AM
Old 12-30-2013
Hi

Thanks for replying

The input looks like below
Code:
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  SEV=NONE                                                                 
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
                                                                           
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  TFWD=N;OV=N;~                                                            
  COUNT=3;ATOM=KLZCPU.CPUID;TFWD=Y;SEV=Critical;TDST=0;                    
  COUNT=3;ATOM=KLZCPU.CPUID;TFWD=Y;SEV=Warning;TDST=0;                     
  COUNT=3;ATOM=LNXPROC.CMD;TFWD=Y;SEV=Critical;TDST=0;                     
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Critical;TDST=0;                            
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Warning;TDST=0;                             
  COUNT=3;TFWD=Y;SEV=Warning;TDST=0;                                       
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Warning;TDST=0;                             
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Critical;TDST=0;                            
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Critical;TDST=0;                            
  ATOM=KLZNET.FNAME;TFWD=Y;SEV=Critical;TDST=0;                            
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Critical;TDST=0;                            
  COUNT=3;TFWD=Y;SEV=Critical;TDST=0;                                      
  COUNT=4;ATOM=LNXPROC.PID;TFWD=Y;SEV=Critical;TDST=0;                     
  COUNT=3;ATOM=KLZNET.FIPADDR;TFWD=Y;SEV=Critical;TDST=0;                  
  COUNT=3;TFWD=Y;SEV=Warning;TDST=0;                                       
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Critical;TDST=0;                            
  ATOM=LNXPROC.CMDU;TFWD=Y;SEV=Critical;TDST=0;                            
  COUNT=3;TFWD=Y;SEV=Critical;TDST=0;                                      
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Critical                                                             
  SEV=Critical                                                             
  SEV=Critical                                                             
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Critical                                                             
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Critical                                                             
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Warning;ATOM=KUDDBASEGROUP00.db_name                                 
  SEV=Warning;ATOM=KUD_DB2_Database00.db_name                              
  SEV=Warning;ATOM=KUDBUFFERPOOL00.db_name                                 
  SEV=Warning;ATOM=KUD_DB2_Buffer_Pool.db_name                             
  SEV=Critical                                                             
  SEV=Critical                                                             
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Critical                                                             
  SEV=Critical                                                             
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Critical                                                             
  SEV=Critical                                                             
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Critical                                                             
  SEV=Critical                                                             
  SEV=Warning                                                              
  SEV=Warning                                                              
  SEV=Critical                                                             
  SEV=Critical                                                             
  SEV=Critical;ATOM=KUDDBASE00.DBNM                                        
  SEV=Warning;ATOM=KUDDBASE00.DBNM                                         
  SEV=Critical;ATOM=KUD3437500.UA1                                         
  SEV=Warning;ATOM=KUD3437500.UA1                                          
  SEV=Critical;ATOM=KUD3437600.UUA1                                        
  SEV=Critical;ATOM=KUDDBASE01.DBNM                                        
  SEV=Warning;ATOM=KUD3437600.UUA1                                         
  SEV=Warning;ATOM=KUDDBASE01.DBNM                                         
  SEV=Critical;ATOM=KUD3437600.UUA1                                        
  SEV=Critical;ATOM=KUDDBASE01.DBNM                                        
  SEV=Warning;ATOM=KUD3437600.UUA1                                         
  SEV=Warning;ATOM=KUDDBASE01.DBNM                                         
  SEV=Critical;ATOM=KUD3437500.UA1                                         
  SEV=Critical;ATOM=KUDDBASE00.DBNM                                        
  SEV=Critical;ATOM=KUDDBASE01.DBNM                                        
  SEV=Warning;ATOM=KUDDBASE01.DBNM                                         
  SEV=Critical;ATOM=KUD3437600.UUA1                                        
  SEV=Warning;ATOM=KUD3437600.UUA1                                         
  SEV=Critical;ATOM=KUD3437600.UUA1                                        
  SEV=Critical;ATOM=KUDDBASE01.DBNM                                        
  SEV=Warning;ATOM=KUD3437600.UUA1                                         
  SEV=Warning;ATOM=KUDDBASE01.DBNM                                         
  SEV=Critical;ATOM=KUD3437600.UUA1

I am going in Loops and assigning the values of Sev ATOM and Count to 3 variables in each line and

varSEV=... (should get CRITCAL for line having SEV=CRITICAL)
varCount=... (should get 2 for line having COUNT=2)
varATOM=... (should get KUDDBASEGROUP00.db_name for line having ATOM=KUDDBASEGROUP00.db_name)

I was trying using sed and regex but failed miserably and two days gone in this (I thought will be simple thing)

Please help

Last edited by Franklin52; 12-30-2013 at 11:57 AM.. Reason: Please use code tags
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to assign value to a variable with row(using -n) returned by sed

Hi Friends, REQUIREMENT: Want to delete files from the current directory match with the same in the file test.txt set -x i=1 echo "i=$i" COUNT=`sed -n '$=' test.txt` echo "Count=$COUNT" while do "## Here is error##" FILETOREMOVE=`sed -n \'$i,1p\' test.txt` echo $FILETOREMOVE... (5 Replies)
Discussion started by: sourabhsharma
5 Replies

2. Shell Programming and Scripting

sed to awk (regex pattern) how?

Hello, I am trying to covert a for statement into a single awk script and I've got everything but one part. I also need to execute an external script when "not found", how can I do that ? for TXT in `find debugme -name "*.txt"` ;do FPATH=`echo $TXT | sed 's/\(.*\)\/\(.*\)/\1/'` how... (7 Replies)
Discussion started by: TehOne
7 Replies

3. Shell Programming and Scripting

How to assign the Pattern Search string as Input Variable

guys, I need to know how to assing pattern matched string as an input command variable. Here it goes' My script is something like this. ./routing.sh <Server> <enable|disable> ## This Script takes an input <Server> variable from this line of the script ## echo $1 | egrep... (1 Reply)
Discussion started by: raghunsi
1 Replies

4. UNIX for Dummies Questions & Answers

blank space in regex pattern using sed

why does sed 's/.* //' show the last word in a line and sed 's/ .*//' show the first word in a line? How is that blank space before or after the ".*" being interpreted in the regex? i would think the first example would delete the first word and the next example would delete the second... (1 Reply)
Discussion started by: glev2005
1 Replies

5. Shell Programming and Scripting

SED Replacing all but one regex match on a line or specific matches

Hi, I'm attempting to rename some files that have spaces in them. Without linking sed commands together is it possible to replace the first three "." to " ". File.name.is.long.ext -> File name is long.ext I can get the desired effect with echo "File.name.is.long.ext" | sed 's/\./ /g;s/... (5 Replies)
Discussion started by: vectox
5 Replies

6. Shell Programming and Scripting

SED: Pattern repitition regex matching

Fairly straightforward, but I'm having an awful time getting what I thought was a simple regex to work. I'll give the command I was playing with, and I'm aware why this one doesn't work (the 1,3 is off the A-Z, not the whole expression), I just don't know what the fix is: Actual Output(s): $... (5 Replies)
Discussion started by: Vryali
5 Replies

7. Shell Programming and Scripting

Why regex pattern doesn't work in find?

$ find /opt/data_* -maxdepth 3 -type d -name "main*" 2> /dev/null /opt/data_025/maindblogs /opt/data_026/maindblogs /opt/data_027/maindblogs /opt/data_028/maindblogs $ find /opt/data_* -maxdepth 3 -type d -name "rvlogs*" 2> /dev/null /opt/data_002/prod/rvlogs2_archive... (4 Replies)
Discussion started by: urello
4 Replies

8. Shell Programming and Scripting

How to find a file with a specific pattern for current sysdate & upon find email the details?

I need assistance with following requirement, I am new to Unix. I want to do the following task but stuck with file creation date(sysdate) Following is the requirement I need to create a script that will read the abc/xyz/klm folder and look for *.err files for that day’s date and then send an... (4 Replies)
Discussion started by: PreetArul
4 Replies

9. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies
All times are GMT -4. The time now is 02:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy