Sponsored Content
Top Forums Shell Programming and Scripting Convert .../($var1|$var2)/... regex to string Post 302680725 by Lem on Thursday 2nd of August 2012 08:26:44 AM
Old 08-02-2012
"Your shell program"... Which shell?

For instance, in bash you can use brace expansion:

Code:
echo /{ar,az,dua,en,fa,fr}/{index,index2}.php
/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

If you have stored the string in a variable, say $input, then:

Code:
input="/{ar,az,dua,en,fa,fr}/{index,index2}.php"
eval echo "$input"
/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

So, first change the format from "/(ar|az|dua|en|fa|fr)/(index|index2).php" to "/{ar,az,dua,en,fa,fr}/{index,index2}.php". After you've checked that neither "{", "}", nor "," are present in your paths, do it this way:

Code:
input_forBE="$(sed -e 's/(/{/g' -e 's/)/}g' -e 's/|/,/g'  <<<$input)"

Then use bash brace expansion, as shown above. For instance:
Code:
eval ls "$input_forBE"
ls: impossibile accedere a /ar/index.php: File o directory non esistente
ls: impossibile accedere a /ar/index2.php: File o directory non esistente
ls: impossibile accedere a /az/index.php: File o directory non esistente
ls: impossibile accedere a /az/index2.php: File o directory non esistente
ls: impossibile accedere a /dua/index.php: File o directory non esistente
ls: impossibile accedere a /dua/index2.php: File o directory non esistente
ls: impossibile accedere a /en/index.php: File o directory non esistente
ls: impossibile accedere a /en/index2.php: File o directory non esistente
ls: impossibile accedere a /fa/index.php: File o directory non esistente
ls: impossibile accedere a /fa/index2.php: File o directory non esistente
ls: impossibile accedere a /fr/index.php: File o directory non esistente
ls: impossibile accedere a /fr/index2.php: File o directory non esistente

--
Bye

Last edited by Lem; 08-02-2012 at 09:33 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
APACHE_LOOKUP_URI(3)							 1						      APACHE_LOOKUP_URI(3)

apache_lookup_uri - Perform a partial request for the specified URI and return all info about it

SYNOPSIS
object apache_lookup_uri (string $filename) DESCRIPTION
This performs a partial request for a URI. It goes just far enough to obtain all the important information about the given resource. This function is supported when PHP is installed as an Apache module or by the NSAPI server module in Netscape/iPlanet/SunONE webservers. PARAMETERS
o $filename - The filename (URI) that's being requested. RETURN VALUES
An object of related URI information. The properties of this object are: ostatus othe_request ostatus_line omethod ocontent_type ohandler ouri ofilename opath_info oargs oboundary ono_cache ono_local_copy oallowed osend_bodyct obytes_sent obyterange oclength ounparsed_uri omtime orequest_time EXAMPLES
Example #1 apache_lookup_uri(3) example <?php $info = apache_lookup_uri('index.php?var=value'); print_r($info); if (file_exists($info->filename)) { echo 'file exists!'; } ?> The above example will output something similar to: stdClass Object ( [status] => 200 [the_request] => GET /dir/file.php HTTP/1.1 [method] => GET [mtime] => 0 [clength] => 0 [chunked] => 0 [content_type] => application/x-httpd-php [no_cache] => 0 [no_local_copy] => 1 [unparsed_uri] => /dir/index.php?var=value [uri] => /dir/index.php [filename] => /home/htdocs/dir/index.php [args] => var=value [allowed] => 0 [sent_bodyct] => 0 [bytes_sent] => 0 [request_time] => 1074282764 ) file exists! PHP Documentation Group APACHE_LOOKUP_URI(3)
All times are GMT -4. The time now is 09:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy