Sponsored Content
Top Forums Shell Programming and Scripting Convert .../($var1|$var2)/... regex to string Post 302680639 by Ghadamyari on Thursday 2nd of August 2012 06:46:09 AM
Old 08-02-2012
Java Convert .../($var1|$var2)/... regex to string

Hello,

In one part of my shell program I need to translate many of lines in the following pattern :
Code:
/(folder1|...|folderN)/(sub1|...|subN)/.../(file1|...|fileN)

into strings :
Code:
/folder1/sub1/.../file1
/folder1/sub1/.../...
/folder1/sub1/.../fileN
...
/folderN/subN/.../fileN

the folderX/fileX is just a variable and it could be any name.

Please help me obtaining the shell script.

sample input :
Code:
/(ar|az|dua|en|fa|fr)/(index|index2).php
/(ar|az|dua|en|fa|fr)/administrator/(index|index2).php
/(ar|fa)/modules/(mod_tabmods|mod_tabs|mod_base|mod_secure)/scripts/(importer|uploader).php

desired output :
Code:
/ar/index.php
/ar/index2.php
/az/index.php
/az/index2.php
/dua/index.php
/dua/index2.php
/en/index.php
/en/index2.php
/fa/index.php
/fa/index2.php
/fr/index.php
/fr/index2.php
/ar/administrator/index.php
/ar/administrator/index2.php
/az/administrator/index.php
/az/administrator/index2.php
/dua/administrator/index.php
/dua/administrator/index2.php
/en/administrator/index.php
/en/administrator/index2.php
/fa/administrator/index.php
/fa/administrator/index2.php
/fr/administrator/index.php
/fr/administrator/index2.php
/ar/modules/mod_tabmods/scripts/importer.php
/ar/modules/mod_tabmods/scripts/uploader.php
/ar/modules/mod_tabs/scripts/importer.php
/ar/modules/mod_tabs/scripts/uploader.php
/ar/modules/mod_base/scripts/importer.php
/ar/modules/mod_base/scripts/uploader.php
/ar/modules/mod_secure/scripts/importer.php
/ar/modules/mod_secure/scripts/uploader.php
/fa/modules/mod_tabmods/scripts/importer.php
/fa/modules/mod_tabmods/scripts/uploader.php
/fa/modules/mod_tabs/scripts/importer.php
/fa/modules/mod_tabs/scripts/uploader.php
/fa/modules/mod_base/scripts/importer.php
/fa/modules/mod_base/scripts/uploader.php
/fa/modules/mod_secure/scripts/importer.php
/fa/modules/mod_secure/scripts/uploader.php


Last edited by Ghadamyari; 08-02-2012 at 08:16 AM..
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

*fixed if (( var1 && var2 )) ??

*EDIT -- **FIXEd I must've done something wrong, because it works now.. I punched in "if" in the forum search but nothing came up, so I'm posting it here. Quick question: Can someone correct my syntax. #!/bin/ksh if (( var >= 1 && var <= 5 )); then .................................. (1 Reply)
Discussion started by: yongho
1 Replies

2. Shell Programming and Scripting

Echo var1,var2,var3,var4,var5,var6 in loop help

Hello, I have created numerous variables called $mask1 $mask2... $maskN. I wish to echo these variables, below is the code for the two functions, the first creates the variables and the second echos them. It is the second function which does not work. The line (i believe to be wrong) is in... (1 Reply)
Discussion started by: rorey_breaker
1 Replies

3. Shell Programming and Scripting

(probably stupidly simple) if [ $var1 = $var2 ] problem...

OK, while I'm not new to the Mac or some of the the inner workings of Mac OS X I am quite new to scripting. And while I have "Learning the Bash Shell" by those lovely people at O'Reilly (Cameron Newham et. al.) I'm missing something, I just know I am. Here's the problem: At the beginning of... (2 Replies)
Discussion started by: woodgie
2 Replies

4. UNIX for Dummies Questions & Answers

regex on first string in a variable.

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)
Discussion started by: Endo
1 Replies

5. UNIX for Dummies Questions & Answers

What is this? var2=${var1#??????????}

Googling the answer to this question just doesn't work when Google won't search your symbols for you. Can someone tell me what this command will assign to var2, and where I can find more information about using braces in this way? var2=${var1#??????????} Thanks so much. (2 Replies)
Discussion started by: blondie53403
2 Replies

6. Shell Programming and Scripting

using regex to get part of a string ?

Hi there, i wonder, is it possible to use regular expressions to partially select a string? I have a bunch of server names which look like this server1z-test server2z2 server45z-primary server13z3 I want to extract up to and including the 'z' in the server name, so for example ... (4 Replies)
Discussion started by: hcclnoodles
4 Replies

7. Shell Programming and Scripting

BASH regex (convert from working perl version)

Hi there, I need to test that a variable ($VAR) matches a regex mask in BASH. I have the exact thing working in perl (below), but could somebody advise me how i would do the same in BASH ? do i need to use something like egrep ? #!/bin/perl -w my $VAR = "some value"; if ( $VAR =~... (4 Replies)
Discussion started by: rethink
4 Replies

8. Shell Programming and Scripting

concatenate varaibles var1, var2 together to var1 again

HI i like to concatenate the two variables var1=$line (ie 22885068900000652 B86860003OLFXXX592123320081227) var2=$amount (ie 123456) i want to club together both the above varaible var1 & var2 and assign back to var1 right now i am doing like this but it is not working. var1=`echo... (1 Reply)
Discussion started by: kshuser
1 Replies

9. Shell Programming and Scripting

filtering out duplicate substrings, regex string from a string

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)
Discussion started by: kchinnam
8 Replies

10. Shell Programming and Scripting

Convert posix regex to pcre (perl)

In order to clean file from html tags i used the following sed 's/<*>//g' filename Right now i need to do the same from php script so i have to use pcre. How to convert? (1 Reply)
Discussion started by: urello
1 Replies
RE_COMP(3)						     Linux Programmer's Manual							RE_COMP(3)

NAME
re_comp, re_exec - BSD regex functions SYNOPSIS
#define _REGEX_RE_COMP #include <sys/types.h> #include <regex.h> char *re_comp(char *regex); int re_exec(char *string); DESCRIPTION
re_comp() is used to compile the null-terminated regular expression pointed to by regex. The compiled pattern occupies a static area, the pattern buffer, which is overwritten by subsequent use of re_comp(). If regex is NULL, no operation is performed and the pattern buffer's contents are not altered. re_exec() is used to assess whether the null-terminated string pointed to by string matches the previously compiled regex. RETURN VALUE
re_comp() returns NULL on successful compilation of regex otherwise it returns a pointer to an appropriate error message. re_exec() returns 1 for a successful match, zero for failure. CONFORMING TO
4.3BSD. NOTES
These functions are obsolete; the functions documented in regcomp(3) should be used instead. SEE ALSO
regcomp(3), regex(7), GNU regex manual COLOPHON
This page is part of release 3.27 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. GNU
1995-07-14 RE_COMP(3)
All times are GMT -4. The time now is 10:43 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy