RegEx for text pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting RegEx for text pattern
# 1  
Old 08-26-2009
RegEx for text pattern

Hi,

Please help me write regex for text pattern like


CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3, ...so on

Any advice is Okay!

Thanks in advance.
# 2  
Old 08-26-2009
Code:
echo CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3 | cut -d: -f2

is this ok?
# 3  
Old 08-26-2009
Code:
^contact people:(?:[^\.]*?\.[^\.]*)+

# 4  
Old 08-28-2009
thanks Sweetblood

---------- Post updated 08-28-09 at 02:40 PM ---------- Previous update was 08-27-09 at 03:57 PM ----------

Quote:
Originally Posted by sweetblood
Code:
^contact people:(?:[^\.]*?\.[^\.]*)+


I am trying to test this Regex, there seems to be a problem . I always get a
"XXXX" with my test.txt which has text :

Text:
_________________________

CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3

______________________________



Code:
#!/bin/sh
cat ./test.txt|{
awk '/^CONTACT PEOPLE:(?:[^\.]*?\.[^\.]*)+/ {flag1++}
 END {
                if(flag1==1)
               {
                print"----------------------------------"|"cat>&2"               
               }
                else  
                {
               print"XXXXXXXXXXXXXXXXXXXXXXXXXX"|"cat>&2"                  
                }
        }'
}

-----------------------------------------------------
# 5  
Old 08-29-2009
Quote:
Originally Posted by rider29
...
I am trying to test this Regex, there seems to be a problem . I always get a
"XXXX" with my test.txt which has text :
...
That's because the regex pattern doesn't match the data in your file:

Code:
$ 
$ cat test.txt
CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3
$ 
$ awk '/^CONTACT PEOPLE:(?:[^\.]*?\.[^\.]*)+/' test.txt
$ 
$

The regex shown below matches the line; not sure if that's what you are looking for:

Code:
$ 
$ awk '/^CONTACT PEOPLE:([^\.]*?\.[^\.]*)+/' test.txt
CONTACT PEOPLE:first_name1.last_name1,first_name2.last_name2,first_name3.last_name3
$

tyler_durden
# 6  
Old 08-31-2009
of course the pattern matches the OP's data. What was not explained in the original post is that he wanted a pattern for awk which does not support (?Smilie otherwise the pattern you supplied is simply a copy of mine.
# 7  
Old 09-01-2009
thanks to every body. I am not a scripting guy,trying to learn by asking questions . All your posts very Valuable to me.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Regex to identify pattern

Hi In a file I have string in multiple lines. Like below: <?=test.getObjectName("L", "testTBL","D") ?> <?=test.getObjectName("L", "testTBL","testDB", "D") ?> I want to use regex to search for the pattern "<?=test.getObjectName...?>" If the parenthesis has 3 parameters then return 2nd... (5 Replies)
Discussion started by: dashing201
5 Replies

2. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

3. Shell Programming and Scripting

Only Regex pattern match help

Hi We have a tool to monitor logs in our environment. The tool accepts log pattern match only using regex and I accept I am a n00b in that:confused:. I had been banging my head to make it work without much success and at last had to turn on to my last option to post it here. I had got great... (2 Replies)
Discussion started by: radioactive9
2 Replies

4. 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

5. 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

6. Shell Programming and Scripting

RegEx - selective delete around a pattern

I need RegEx to delete text block delimited by "^--" and "^request saved" if the block contained the pattern "FAILED:No air,rail,hotel or car" in the following. Many thanks in advance! company_id=9292 queue_id=72 internationalOnly=0 Building XML... ABC123 Adding passenger first=First ... (1 Reply)
Discussion started by: roshansharma
1 Replies

7. UNIX for Advanced & Expert Users

Regex pattern for multiple digits

Hello, I need to construct a pattern to match the below string (especially the timestamp at the beginning) 20101222100436_temp.dat The below pattern works _temp.dat However I am trying find if there are any other better representations. I tried {14}, but it did not work. I am on... (5 Replies)
Discussion started by: krishmaths
5 Replies

8. Shell Programming and Scripting

Selecting a part of the text (regex pattern, awk, sed)

Hello, let's start by giving you guys a few examples of the text: "READ /TEXT123/ABC123" "READ /TEXT123/ABC123/" "READ TEXT123/ABC123" "READ TEXT123/ABC123/" "READ TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123" "READ /TEXT123/TEXT456/ABC123/" TEXT and ABC can be and I... (5 Replies)
Discussion started by: TehOne
5 Replies

9. 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

10. 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
Login or Register to Ask a Question