Hello ,
Could anyone help me to define the string in regular expression way .
Below is my string
\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
CarloM
October 16, 2013, 10:03am
2
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?
For single line matching:
egrep '^\\rtf1.*\\f0\\fs(16|20)$'
We have to use extended regexp.
Emanuele
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
Perl.
perl -nle 'print if /^\\rtf1/ ... /\\fs(16|20)$/' filename
Jotne
October 17, 2013, 4:32am
6
Using awk
awk '/^\\rtf1/ && /f0\\fs(16|20)$/'
or
awk '/^\\rtf1.*f0\\fs(16|20)$/'
Ok, then:
egrep '^\\rtf1.*fs(16|20)$'
"starts with \rtf1" -> '^\\rtf1'
"ends with fs16 or fs20" -> 'fs(16|20)$'
"any characters in between" -> '.*'
Emanuele