Pattern search (regular expression in UNIX)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Pattern search (regular expression in UNIX)
# 1  
Old 10-16-2013
Pattern search (regular expression in UNIX)

Hello ,

Could anyone help me to define the string in regular expression way .

Below is my string

Code:
\rtf1\ansi\deff0{\fonttbl{\f0\fswiss Helv;}{\f1\fnil MS Sans Serif;}}
{\colortbl ;\red0\green0\blue0;}
\viewkind4\uc1\pard\cf1\lang1033\f0\fs16

The string will always start as \rtf1 and end in either f0/fs16 or f0/fs20

I need to define in patternsearch format in regular expression way

like starting with \rtf1 followed by any numbers of characters and ending with either \f0\fs16 or \f0\fs20

I have tried with \rtf1.fs[0-9][0-9] but its not working

Last edited by Scrutinizer; 10-17-2013 at 04:49 PM.. Reason: code tags
# 2  
Old 10-16-2013
Searching across multiple lines is a bit problematic. Exactly what do you want to string for? Are you just outputting it, replacing it, or taking some action when you find it?
# 3  
Old 10-16-2013
For single line matching:
Code:
egrep '^\\rtf1.*\\f0\\fs(16|20)$'

We have to use extended regexp.

Emanuele
# 4  
Old 10-17-2013
thanks targzeta but its not working

I want to identify any string that starts with
\rtf1 and ends with fs16 or fs20 and any characters in between
# 5  
Old 10-17-2013
Perl.
Code:
 perl -nle 'print if /^\\rtf1/ ... /\\fs(16|20)$/' filename

# 6  
Old 10-17-2013
Using awk
awk '/^\\rtf1/ && /f0\\fs(16|20)$/'
or
awk '/^\\rtf1.*f0\\fs(16|20)$/'
# 7  
Old 10-17-2013
Quote:
Originally Posted by Pratik4891
thanks targzeta but its not working

I want to identify any string that starts with
\rtf1 and ends with fs16 or fs20 and any characters in between
Ok, then:
Code:
egrep '^\\rtf1.*fs(16|20)$'

"starts with \rtf1" -> '^\\rtf1'
"ends with fs16 or fs20" -> 'fs(16|20)$'
"any characters in between" -> '.*'

Emanuele
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular Expression repeat pattern

Hi, I'm struggling with very very simple task but dont know where I'm going wrong. Have the following file numbers.txt 1 12 123 1234 12345 123456 1234567 12345678 123456789 1234567890 9876543210 987654321 98765432 9876543 987654 98765 (1 Reply)
Discussion started by: bobbygsk
1 Replies

2. Shell Programming and Scripting

awk regular expression search

Hi All, I would like to search a regular expression by passing as an i/p variableto AWK. For Example :: 162.111.101.209.9516 162.111.101.209.41891 162.111.101.209.9516 162.111.101.209.9517 162.111.101.209.41918 162.111.101.209.9517 162.111.101.209.41937 162.111.101.209.41951... (7 Replies)
Discussion started by: Girish19
7 Replies

3. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

4. Shell Programming and Scripting

How can awk search a string without using regular expression?

Hello, Awk seem treat the pattern as regular expression, how can awk search not using regular expression? e.g. just represent for "", not "A" or "a" . I don't want to add backslash . (2 Replies)
Discussion started by: 915086731
2 Replies

5. Shell Programming and Scripting

Regular Expression for Random pattern

What would be the regular expression that can search for a Pattern, having 8 characters out of which atleast 1 digit, 1 lower case, 1 upper case letter and 1 special character must be there. But these can occur at any place randomly. Please help me out. I'm using find $dir -name "*.txt" -exec... (0 Replies)
Discussion started by: Pradeep Kr.
0 Replies

6. Shell Programming and Scripting

Validate time pattern using regular expression

Hi, I am new to scripting. please help me in validating the user entered time Pattern Here is the program #!/bin/bash validateTimeFormat() { checkTime=$1 timePattern="::" if ] then echo "Valid time pattern" return 1 else echo "InValid time pattern" return -1 fi } echo "Please... (2 Replies)
Discussion started by: vvenu88
2 Replies

7. Shell Programming and Scripting

validate date pattern using Regular Expression

Hi, i am java guy and new to unix. I want to validate date pattern using Regex expression here is the sample program i have written. #!/bin/sh checkDate="2010-04-09" regex="\\d{4}-\\d{2}-\\d{2}\$" echo $regex if ] then echo "OK" else echo "not OK" fi But the ouput is... (2 Replies)
Discussion started by: vvenu88
2 Replies

8. Shell Programming and Scripting

awk + pattern search with regular expression

Hi , I have a file with "|" (pipe) as a delimeter. I am looking for the record count where 5th field is a number with 15 digit length only. all the records with above requirement is valid rest all are invalid. I need count of valid records and invalid records. Can anyone please help (9 Replies)
Discussion started by: vikash_k
9 Replies

9. Shell Programming and Scripting

Perl Regular Expression Word Search

I'm trying to have my perl script telnet into the network device execute a command then dump the output of the command into a variable. The script then greps for the word "STANDBY". I can't seem to get the script to print out the output because it seems that the script can't find the word... (1 Reply)
Discussion started by: xmaverick
1 Replies

10. Shell Programming and Scripting

Regular Expression to exclude pattern

Hi All I am using regular expressions to determine how to group certain data. I've included an example of the data below. USD_SPTR_2Y_725.5_PUT_EUROPEAN_09Q1|USD||European| CAD_NDX_10Yx1Y_5.5_PUT_EUROPEAN_09Q1|CAD||European| The regular expressions I am using is as follows and this is... (5 Replies)
Discussion started by: kingpin2502
5 Replies
Login or Register to Ask a Question