473,395 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problem with pattern matching in .sh script

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 3121
Try Using in groups which will say something like ( ) ( ) and instead of using [A-Za-Z] try using \w+
Aug 28 '07 #2
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 Expert Mod 2GB
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 Expert 100+
...
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
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
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
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
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
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
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
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
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
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
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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.