Tag Archives: REGEX

Regex to identify word in second position on a line

By gimley

I am interested in finding a regex to find a word in second position on a line. The word in question is या
I tried the following PERL EXPRESSION but it did not work:

Code:

[^[:word:]] या
or
^W या


But both gave Null results
I am giving below a Sample file:

Code:

देना या सौंपना=delegate
तह जमना या जमाना=film
झुकना या झुकाना=slant
घुलना या घोलना=dissolve
घिसना या घिसाना=grate
खुले आम या प्रकट=avow
एड़ लगाना या देना=spur
उभरना या उभारना=heave
उचकाना या झाड़ना=shrug
आना या कुछ करना=mistime
हो जाना या होना=orient
होना या हो जाना=double
लिखना या लगाना=preface
बल या शिकन पड़ना=cockle


I would like the REGEX to single out all lines where the word या occurs in second position.
Many thanks for the help.

From: http://www.unix.com/shell-programming-scripting/221723-regex-identify-word-second-position-line.html

Need a REGEX to increment the file number of a pdf file

By Marcus Aurelius

Hello,

I have a few thousand .pdf files in various folders each have a naming scheme like this:

006_-_Titled_Document_#34_-_September-25-2011-side-1.pdf

In each folder, the number system starts at 001 (as you see on the far left of the file name), and then ends at 999 (maximum .pdf files).

Somewhere in the collection of files say .pdf # 286, I have 286 twice (duplicate). Which screws up my numbering system.

I need a REGEX that I can enter into the shell when I’m in the .pdf directory, and start from say the duplicate # 286 and increment that 2nd duplicate # 286 & all the numbers after that by +1. So that they are all renamed appropriately.

This way I don’t have to go in there and rename each .pdf file manually one by one.

Unfortunately, I am not very good with REGEX and haven’t had much need for it in the past until now.

Would anyone know the best way to automate this .pdf renumbering task? I would appreciate any constructive thoughts on how to accomplish this.

Thank you.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums

Bash Vs. Bourne REGEX: metacharacters escaping

By ConcealedKnight

I am currently reading a very old reference from O’Reilly: Sed and Awk 2nd Edition reprinted in 2000. So far, it’s a solid read and still very relevant. I’d highly recommend this to anyone.

The only problem I have with this book is that I had to resort to bourne shell to get my examples to work since bash wasn’t ubiquitous when the book was written.

So, when I was trying to follow the book example, I get the error in bash on my latest Ubuntu Server distro.

I tried to use a regular expression that looked for any line containing the string, “book” in the bookworks file. It is not my ultimate goal to correctly extract all lines with the string “book” yet as I was following the book examples, which will show me the correct form.

I tried the following command in bash:

Code:

grep " ["[{(]*book[]})"?!.,;:'s]* " bookwords


I get the following error in bash:

Code:

-bash: !.,: event not found


But when I tried the command after switching over to bourne shell, I get no error, and it gave me the output I expected like the one in the book examples. Can someone please tell me why is this happening? I’d like to know what metacharacters are causing this and how I can escape it in Bash? I wish there is a third edition of this book that covers REGEX in bash.

…read more
Source: FULL ARTICLE at The UNIX and Linux Forums