473,503 Members | 1,739 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with pattern matching in .sh script

9 New Member
Hello all,
I am doing a pattern matching for a string in a shell script.
Here an apostrophe ( ' ) is also a part of a string hence it should also be part of the pattern. But somehow i can't seem to be able to include it.
I have tried using the backslash to escape it but to no success.
Also tried putting ' inside two others like this ' ' ' .... but this doesn't work as well.
Please help.

My code look something like this :
Code: ( text )

if( $0 ~ /^"[-a-zA-ZÀ-ÖØ-öø-ÿ<> ;0-9]+"/ )
{
}
else
{
}

The string should should have ( " ) at the start and the end and in between alpha-numeric characters with some special chars.
e.g : "Mont-l'pierre"

Thanks !!
Sid
Aug 28 '07 #1
5 3124
rameshramesh
7 New Member
Try Using in groups which will say something like ( ) ( ) and instead of using [A-Za-Z] try using \w+
Aug 28 '07 #2
rellaboyina
55 New Member
Try Using in groups which will say something like ( ) ( ) and instead of using [A-Za-Z] try using \w+

You can use a backslash character(\) to escape the special meaning of the character ( ' ). It works.
Aug 30 '07 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
Hello all,
I am doing a pattern matching for a string in a shell script.
Here an apostrophe ( ' ) is also a part of a string hence it should also be part of the pattern. But somehow i can't seem to be able to include it.
I have tried using the backslash to escape it but to no success.
Also tried putting ' inside two others like this ' ' ' .... but this doesn't work as well.
Please help.

My code look something like this :
Code: ( text )

if( $0 ~ /^"[-a-zA-ZÀ-ÖØ-öø-ÿ<> ;0-9]+"/ )
{
}
else
{
}

The string should should have ( " ) at the start and the end and in between alpha-numeric characters with some special chars.
e.g : "Mont-l'pierre"

Thanks !!
Sid
Sorry, but this forum is for questions related to Perl scripting, not Shell scripting. Unless of course you have a Perl question?


Could a Moderator please move this posting to either the Linux/Unix/BSD forum or the Misc. Questions forum please? Thank you!

Regards,

Jeff
Aug 30 '07 #4
prometheuzz
197 Recognized Expert New Member
...
Could a Moderator please move this posting to either the Linux/Unix/BSD forum or the Misc. Questions forum please? Thank you!
...
Done.

.......................
Aug 30 '07 #5
forumsaregreat
9 New Member
Firstly sorry for posting the question in the wrong section.

And thanks everyone for your replies / suggestions.
I was facing a strange problem in that the backslash did not escape the ( ' ). Nevertheless I used the hex value of ( ' ) and then it worked.
Very strage to me and also makes the code shabby to read.

Regards,
Sep 3 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
6968
by: gsv2com | last post by:
One of my weaknesses has always been pattern matching. Something I definitely need to study up on and maybe you guys can give me a pointer here. I'm looking to remove all of this code and just...
176
7997
by: Thomas Reichelt | last post by:
Moin, short question: is there any language combining the syntax, flexibility and great programming experience of Python with static typing? Is there a project to add static typing to Python? ...
9
3185
by: Xah Lee | last post by:
# -*- coding: utf-8 -*- # Python # Matching string patterns # # Sometimes you want to know if a string is of # particular pattern. Let's say in your website # you have converted all images...
7
3529
by: Niko | last post by:
Hi , I am writing script using multiple pattern matching. I need to replace the $_ =~ few times. Example: sub xx { open (TEMPF,"> $T_FILE");
1
2719
by: Henry | last post by:
I have a table that stores a list of zip codes using a varchar column type, and I need to perform some string prefix pattern matching search. Let's say that I have the columns: 94000-1235 94001...
5
5733
by: olaufr | last post by:
Hi, I'd need to perform simple pattern matching within a string using a list of possible patterns. For example, I want to know if the substring starting at position n matches any of the string I...
2
1241
by: ctiggerf | last post by:
I am having a regular expression problem with a bit of code I'm working on. I was able to get a similar piece of code working in perl, but now I'm trying to convert it over. Basically what I'm...
2
1092
by: i80and | last post by:
I'm working on a program to remove tags from a HTML document, leaving just the content, but I want to do it simply. I've finished a system to remove simple tags, but I want all CSS and JS to be...
5
5029
by: pramodkh | last post by:
Hi All I am trying to match a pattern in a file and insert a line. If the pattern matches then insert a line before the matching pattern line. for example, I have the following content in a...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7087
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3156
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.