Regex to hunt for a string in the right hand column
I have a database which has the following structure
as in the example below
I want to identify all instances of a hyphen in the right-hand column i.e. IPA and which are missing in the left-hand column i.e. the English Words. A small example is given below
I work under windows but a Perl or even Unix regex could help. Many thanks
With your sample data contained in a file named database.txt, any of the following commands:
produce the output:
As always, without knowing what utility will be using a regular expression, we don't know the type of regular expression nor how that RE will need to be delimited to get the results you want.
Thanks a lot for your kind help. I am sorry I should have been more explicit.
I use Ultraedit which allows for regexes both under PERl and UNIX environments
Basically I want to plug in the regex in the editor and write a macro which will remove all such unwanted hyphens.
The regexes you provided work with Grep or Awk but when I plug them into the editor as Unix regexes, they do not identify correctly although the syntax seems correct.
Do not find a hyphen in column one but find in column 2
Thanks once again for your help
Thanks a lot for your kind help. I am sorry I should have been more explicit.
I use Ultraedit which allows for regexes both under PERl and UNIX environments
Basically I want to plug in the regex in the editor and write a macro which will remove all such unwanted hyphens.
The regexes you provided work with Grep or Awk but when I plug them into the editor as Unix regexes, they do not identify correctly although the syntax seems correct.
Do not find a hyphen in column one but find in column 2
Thanks once again for your help
Please, try the following:
Or test with any regex engine that suport Perl regex.
I am carrying the query a bit further as a matter of curiosity. The regex string in Perl
checks for a hyphen on the right hand side of the database delimited by an
sign
whereas no hyphen exists in the left hand side.
Out of curiosity I reversed the regex as under to find all instances in the database where a hyphen exists in the left hand side but not in the right hand side as in the examples below:
I tried the regex
but it failed and did not detect anything. Why did this fail?
What modification is needed? Thanks a lot for satisfying my curiosity.
...
...
I reversed the regex as under to find all instances in the database where a hyphen exists in the left hand side but not in the right hand side as in the examples below:
I tried the regex
but it failed and did not detect anything. Why did this fail?
What modification is needed? ...
A couple of things to note first:
(1) The "/" before the "=" is usually incorrect. By default, Perl uses forward-slashes as "pattern terminators" to match a pattern, like so:
So a forward-slash inside the pattern will not work by default.
You could make it work, however, if you use non-default pattern terminators with the "m" (match) operator, like so:
Many other pattern terminators and even "pairs" are allowed: "[]", "{}", "()", "!!" etc.
(2) Note that the forward-slash was not present inside the pattern in the original solution. So, if your intention was to escape the "=", then the correct character is the back-slash "\". And even then, the "=" does not need to be escaped in Perl. It does not hold any special meaning.
So, now the regex is reduced to:
(3) Next, notice the caret ("^"). It is a start-of-line anchor. It does not match any character. It matches a position: the "start of pattern". Hence it is always used at the start of the pattern. If you use it within the pattern, it will not match anything.
So, now the regex is reduced to:
(4) Now if you take a step back and look at the original regex:
In the original regex, we stop the moment we reach a "-" on the right hand side. We found what we wanted, so we take the relevant action.
But when you switch the patterns around the "=" character, that may not be true. So you put something after the "-" character on the left hand side, like so:
(5) Finally, you want to ensure that the word on the right hand side does not have any hyphens. The regex above matches a "word" on the right hand side, but if that "word" is followed by a hypen, it will still match it.
To ensure that you have a word without any hyphens on the right hand side till the end of the string, you put a "end of pattern" anchor: "$".
It is the counterpart of the "start of pattern" anchor: "^".
So now the regex becomes:
And it should work with your data:
You could, alternatively use the regex
Last edited by durden_tyler; 04-04-2017 at 02:39 PM..
Hi all,
I want to extract rows with the pattern ALPHANUMERIC/ALPHANUMNERIC in the 2nd column.
I dont wan rows with more than 1 slash or without any slash in 2nd column.
a a/b
b a/b/c
c a/b//c
d t/y
e r
f /f
I came up with the regex
grep '\/$' file
a a/b
b a/b/c
d t/y (3 Replies)
Have Pipe Delimited File:
> BRYAN BAKER|4/4/2015|518 VIRGINIA AVE|TEST
> JOE BAXTER|3/30/2015|2233 MockingBird RD|ROW2On 3rd column where the address is located, I want to add a space after every numeric value - basically doing a "s//&\ / ":
> BRYAN BAKER|4/4/2015|5 1 8 VIRGINIA AVE|TEST
> JOE... (5 Replies)
Hi to you all,
I'm just struggling with a regex problem and I'm pretty sure that I'm missing sth obvious... :confused:
I need a regex to feed my grep in order to find lines that contain one string but not the other.
Here's the data example:
2015-04-08 19:04:55,926|xxxxxxxxxx| ... (11 Replies)
Hi,
I have pipe separated file which contains some data having comma(,) in it. I want to remove the comma(,) only from particular column without changing data in other columns.
Below is the sample data file, I want to remove the comma(,) only from 5th column.
$ cat file1
ABC | DEF, HIJ|... (6 Replies)
Hello,
I am working on an Urdu to Hindi dictionary which has the following structure:
a=b
a=c
n=d
n=q
and so on.
i.e. Headword separated from gloss by a =
I am giving below a live sample
بتا=बता
بتا=बित्ता
بتا=बुत्ता
بتان=बतान
بتان=बितान
بتانا=बिताना
I need the following... (3 Replies)
My input contains a single word lines.
From each line
data.txt
prjtestBlaBlatestBlaBla
prjthisBlaBlathisBlaBla
prjthatBlaBladpthatBlaBla
prjgoodBlaBladpgoodBlaBla
prjgood1BlaBla123dpgood1BlaBla123
Desired output -->
data_out.txt
prjtestBlaBla
prjthisBlaBla... (8 Replies)
I am attempting to convert rewrite rules to Nginx, and since due to the mass amount of rewrites we must convert, I've been trying to write a script to help me on a specific part, easily.
So far I have this:
rewrite ^action/static/(+)/$ staticPage.php?pg=$1&%$query_string;
What I want done... (5 Replies)
Hi all, this is driving me nuts.
I need to evaluate if a variable in a shell script has a heading s or m character e.g. s92342394 or m9233489 if so then I need to get rid of them. I'm quite familiar with PERL and could do it there in 3 mins but I have not found a decent way to do this in a shell.... (1 Reply)
Hi,
I remember once seeing a way to get the left most string in a word.
Let's say: a="First.Second.Third" (separated by dot)
echo ${a#*.} shows --> Second.Third
echo ${a##*.} shows --> Third
How do I get the the left most string "First" Or "First.Second" ???
Tried to replace #... (2 Replies)