Problem with pattren Matching


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problem with pattren Matching
# 1  
Old 11-26-2006
Problem with pattren Matching

I have a set of programs and there coressponding MAPSETs
i tried grep on the all the programs and got the following out put
from this i want to extract only the Program Name and Mapset name {i.e. the word in (' ') after MAPSET }

There or some cases where u have no ( after MAPSET that need to be ignored

input :

A:003150 EXEC CICS RECEIVE MAPSET ('M00DA01') MAP ('DA0001 ') P00DA01
A:004370 EXEC CICS SEND MAPSET ('M00DA01') P00DA01
B:002060 MAPSET ('M0201A')
B:005280 MAPSET ('M0201A')
C:002060 MAPSET ('M0202A')
F: *** M0601A - DEAL INCEPTION MAPSET
G: MAPSET('M0601A')
G: MAPSET('M0601A')
E: MAPSET ('M0602A')
G: MAPSET ('M0601A')
K:011070 MAPSET('M0607A')
L:014510 MAPSET('M0605A')
M:000189 EXEC CICS RECEIVE MAP('M1101A1') MAPSET('M1101A') END-EXEC.
M:000695 EXEC CICS SEND MAP('M1101A1') MAPSET('M1101A')
O: * MAPSET -> M1214A / MAP(S) -> M1214A1 *


Output :


A: M00DA01
B: M0201A
C: M0202A
G: M0601A
E: M0602A
K: M0607A
L: M0605A
M: M1101A
# 2  
Old 11-27-2006
I'm sure there must be a cleaner way to do this, but a sed expert I'm not - I did enjoy dusting off the old regexp reference, though.

If you want to sort on field 1 (the A:, B:, etc), change the 'sort -k2' to 'sort -k1'.

Code:
#! /bin/sh

sed -n "/('.*')/p" | \
 sed -e "s/^\(.\:\).*MAPSET *('\([a-zA-Z0-9]*\)'.*$/\1 \2/g" | \
 sort -k2 -u

Assuming it's named "tmp.sh", run it like './tmp.sh <input-file'
# 3  
Old 11-27-2006
Code:
sed -n -e "s/.*MAPSET *('\([^']*\)'.*/\1/p" | sort -u

# 4  
Old 11-27-2006
that give only the mapset,It does not give the program name

i wanted some thing like

A: M00DA01
B: M0201A
C: M0202A
G: M0601A
# 5  
Old 11-27-2006
vino, I knew that could be done in one line. Here's a slightly-updated version of yours that does the same as my earlier attempt:
Code:
 sed -n -e "s/\(.:\).*MAPSET *('\([^']*\)'.*/\1 \2/p" <input-file | sort -k2 -u

# 6  
Old 11-27-2006
one more,

Code:
sed -e "s/.*MAPSET *('//;s/').*//" filename| sed -n '/^M.*/p' | sort -u

# 7  
Old 11-27-2006
you can modify vino's solution :

Code:
sed -n -e "s/\(.*\):.*MAPSET *('\([^']*\)'.*/\1: \2/p" filename | sort -u

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Remove lines with Pattren Matching

Hi , I need to remove the lines that matches the pattern TABLEEXCLUDE *.AQ$_*_F ; * is wildcard, it can be any word. For example, I have following file: TABLEEXCLUDE THOT.AQ$_PT_ADDR_CLEANUP_QTAB2_F ; TABLEEXCLUDE THOT.AQ$_MICRO_SERVICE_QT_F ; TEST TABLEEXCLUDE... (1 Reply)
Discussion started by: rcc50886
1 Replies

2. Shell Programming and Scripting

Replace a string on specific lines which match a pattren

Hi Experts, I have a file which contains a pattern multiple times i.e. matchthispattren. If a line is matched with this pattern. I want a number in 1234567890 to 123456789 in that line. (Basically remove the last digit from that number. Please help. Thanks, Varun (1 Reply)
Discussion started by: varun22486
1 Replies

3. UNIX for Dummies Questions & Answers

How to use sed to look for the particular pattren and convert?

Hi , How do i use sed on a tsv file and look for the date format mm/dd/yyyy and convert it to yyyy-mm-dd. There are around 15 colums in that file and two colums need to be converted. i tried using this but didnt work.Can some one tweek it. sed -e "s_\(..\)\-\(..\)\-\(..\)_\3-\1-\2_" My... (8 Replies)
Discussion started by: vikatakavi
8 Replies

4. Shell Programming and Scripting

Pattern matching problem

if i have to do pattern match for file name with digit alphanumeric value like this File_1234.csv File_12sd45rg.csv i am using this File_*.csv and File_*.csv for digit pattern match. when i am doing pattern match for the digit then both alphanumeric match and digit match is coming. ... (3 Replies)
Discussion started by: ramsavi
3 Replies

5. Shell Programming and Scripting

Pattern matching problem

Hi I need a bash script that can search through a text file for all lines starting with 71502FSC1206 on every line it finds starting with this I need to place a letter F at the 127 position on that line. Thanks Paul (6 Replies)
Discussion started by: firefox2k2
6 Replies

6. UNIX for Dummies Questions & Answers

Get the previous word from the search pattren

Hi, How do i find the previous worlds from the searched pattrens? Input:- Create or replace procedure some tesx. search work is procedure(case insencitive). output:- Create or replace (8 Replies)
Discussion started by: manasa_vs
8 Replies

7. Shell Programming and Scripting

pattern matching problem

# cat email.txt | grep -i "To:" To: <test@example.com> # cat email.txt | grep -i "Subject" Subject: Test Subject: How are you. I need to print only test@example.com from To field need to eliminate "< & >" from To field and need to print entire subject after Subject: It should be #... (7 Replies)
Discussion started by: mirfan
7 Replies

8. Shell Programming and Scripting

find and replace pattren in file

Hi, I have the input file having data as follow: file1.txt 001 aaa_1:abcd 002 bbb_2:abcd I want output as, 001xabcd 002xabcd Here iam trying to replace "{1 space}{alphanumeric string with underscore}{:}" with characrter "x". I tried to achieve this using sed;but Iam not getting this... (5 Replies)
Discussion started by: gopalss
5 Replies

9. Shell Programming and Scripting

negate * with in pattren matching...

Hi Every one I have a file in the following manner... AAAAAA*PERFORM WRITEQ BBDFDD*PERFOMF WRITEQ FFFF *PERFOMF WRITEQ i want to find the lines which donot have * in 7th position.. I have tried this but some problem i think... grep '......*WRITEQ' INpFIle... any 6 chars not... (7 Replies)
Discussion started by: pbsrinivas
7 Replies

10. Shell Programming and Scripting

Search for a Pattren in the files.

Hi Guys, Can you please helpme with this: I would like to read all the files in a directory and need to search for a pattern, Can we use the grep at folder level. Thanks in advance. :) Sat. (2 Replies)
Discussion started by: sbasetty
2 Replies
Login or Register to Ask a Question