Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Expand Variables and Wildcards into another variable. Post 303035138 by chetanojha on Wednesday 15th of May 2019 05:43:23 AM
Old 05-15-2019
Expand Variables and Wildcards into another variable.

Dear Forum members,


I am having trouble getting the complete filename (and directory path) in a variable.



Output directory mentioned in the code have three files:

Code:
DISPLAY_CITY_DETAILS_15-05-2019-08-29-26_MIGRATE_london.out
DISPLAY_CITY_DETAILS_15-05-2019-08-29-26_MIGRATE_paris.out
DISPLAY_CITY_DETAILS_15-05-2019-08-29-26_MIGRATE_rome.out

******************************************************
Code is as shown below:
I am tryin to get get the full path of the above files (including directory path in variable file_path).

Code:

output_dir=$HOME'/country/city/'

while IFS= read -r city_name
do
    
 ## None of the below command  worked.    



     file_path=`${output_dir}/*MIGRATE*${city_name}*.out`
    # eval file_path=`${output_dir}/*MIGRATE*${city_name}*.out`
    # file_path=${eval echo `ls ${output_dir} | grep "MIGRATE"`}
    # eval file_path=`ls ${output_dir} | grep "MIGRATE"`
       
    echo $file_path
 
done < ${city_list}    

##  city_list is the list of cities for which I want to display details

Can anybody help with the command?

Thanks.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How can I put wildcards in an if statement that uses variables?

With the if statement: if How can I make it so it accepts a wildcard after the ${CURR_DAY_MONTH} variable? Putting a -f /webtrends/SUN/mrw2/access.${CURR_DAY_DAY}${CURR_DAY_MONTH}* won't work, right? I think I need some kind of special character so it knows the wildcard is... (3 Replies)
Discussion started by: LordJezo
3 Replies

2. Shell Programming and Scripting

how to seperate a variable in 2 variables

Dear all, i dont know how to split one variable value in 2 variable. please send me any example. variable1= "abcde developer" now i want to seperate the values and seperator is space. (6 Replies)
Discussion started by: intikhabalam
6 Replies

3. UNIX for Dummies Questions & Answers

how to expand environment variables in a file?

I am new to unix and would appreciate if someone could help. I have an environment variable SourceFilePath=/db1/Src/test set on the unix server. I want to expand this SHELL variable in a file using any command sed, awk etc File contents is as follows: var=$SourceFilePath/file.txt ... (2 Replies)
Discussion started by: debbie15
2 Replies

4. UNIX for Dummies Questions & Answers

Using wildcards in variables in zsh

Probably a stupid question... how do I use a wildcard in a variable in zsh? If I do: var=* echo $var in bash, it will print all files/directories in the current directory. If I do it in zsh, it will only output an asterisk without the wildcard functionality. Thanks in advance! (1 Reply)
Discussion started by: RainbowLAr
1 Replies

5. Shell Programming and Scripting

For loop using input file doesn't expand variables

Hi, I'm using a for loop reading from an input file that contains files, whose path includes a variable name. But the for loop doesn't expand the variable and therefore can't find the file. Here's an example: File BACKUPFILES /home/John/alpha /home/Sue/beta... (8 Replies)
Discussion started by: Hesiod
8 Replies

6. Shell Programming and Scripting

Expand an environment variable in sed, when the variable contains a slash

I'm trying to make a sed substitution where the substitution pattern is an environment variable to be expanded, but the variable contains a "slash". sed -e 's/<HOME_DIRECTORY>/'$HOME'/'This gives me the following error: sed: -e expression #1, char 21: unknown option to `s'Obviously this is... (2 Replies)
Discussion started by: Ilja
2 Replies

7. Shell Programming and Scripting

dynamic variables - eval - expand etc.

Hello, so i'm making a script, using dynamic variables and trying to expand them. So far it hasn't worked out too well so it seems that I need some help from you, the elite. Example: #!/bin/sh counter=0 until (($counter>5)) counter2=1 until (($counter2>6)); do if ;... (5 Replies)
Discussion started by: TehOne
5 Replies

8. Shell Programming and Scripting

How to set a variable name from another variables value?

Experts, I want to set value of variables like this in bash shell: i=5 ; L=100 I want variable d5 (that is d(i) ) to be assign the value of $L , d$i=$L ; echo $d5 Not working Thanks., (3 Replies)
Discussion started by: rveri
3 Replies

9. Shell Programming and Scripting

Variable variables

Hello, Can you please help here? DAY=$1 MONTH_MONDAY_YEAR = 1 2 3 4 for i in ${MONTH_${DAY}_YEAR} do echo ${i} done ./test.sh MONDAY ./test.sh: line 3: MONTH_MONDAY_YEAR: command not found ./test.sh: line 10: ${MONTH_${DAY}_YEAR}: bad substitution (6 Replies)
Discussion started by: vino_hymi
6 Replies

10. Shell Programming and Scripting

How to handle grepping variable data containing wildcards?

I have a lot of files with keywords and unique names. I'm using a shell script to refer to a simple pattern file with comma separated values in order to match on certain keywords. The problem is that I don't understand how to handle the wildcard values when I want to skip over the unique names. ... (5 Replies)
Discussion started by: abercrom
5 Replies
CPAN::Inject(3pm)					User Contributed Perl Documentation					 CPAN::Inject(3pm)

NAME
CPAN::Inject - Base class for injecting distributions into CPAN sources SYNOPSIS
# Create the injector my $cpan = CPAN::Inject->new( sources => '/root/.cpan/sources', # Required field author => 'LOCAL', # The default ); # Add a file to the user $cpan->add( file => 'some/random/Perl-Tarball-1.02.tar.gz' ); # What would have have to use when installing # $path = 'LOCAL/Perl-Tarball-1.02.tar.gz'; my $path = $cpan->install_path( 'some/random/Perl-Tarball-1.02.tar.gz' ); DESCRIPTION
Following the release of CPAN::Mini, the CPAN::Mini::Inject module was created to add additional distributions into a minicpan mirror. While it was created for use with a minicpan mirror, similar functionality can be reused in other situations. CPAN::Inject replicates the basics of this functionality. Specifically, it takes an arbitrary tarball and adds it to the CPAN sources directory for a particular author, and then add the new file to the CHECKSUMS file. It does not reimplement the logic to add files to the indexes. The initial use this module was created for was to inject tarballs into the CPAN sources directory for the reserved LOCAL user, so that the can be installed via the CPAN shell, with automated recursion to CPAN dependencies. But although the number of functions is limited (current only "add" exists, with the others to be added as needed) the implementation is very generic and sub-classable, so that it can be reused in other situations. METHODS
new # Create the injector for the default LOCAL author $cpan = CPAN::Inject->new( sources => '/root/.cpan/sources', ); # Create the injector for a specific author $cpan = CPAN::Inject->new( sources => '/root/.cpan/sources', author => 'ADAMK', ); The "new" constructor takes a set of named params and create a cpan injection object. * sources - The compulsory "sources" param should be the path to a directory that is the root of a mirror (or a partial mirror such as a CPAN::Cache or a CPAN::Mini). To retain the permissions and ownership integrity of the sources tree, you must be the owner of the "sources" directory in order to inject the distribution tarballs. * author - The optional "author" param should be the CPAN id of an author. By default, the reserved local CPAN id "LOCAL" will be used. The author provided will be used as a default in all further actions. Returns a "CPAN::Inject" object, or throws an exception on error. from_cpan_config The "from_cpan_config" constructor loads the CPAN.pm configuration file, and uses the data contained within to specific the sources path for the object. This constructor is otherwise the same. Returns a CPAN::Inject object on success, or throws an exception on error. sources The "sources" accessor returns the path to the root of the directory tree. author The "author" accessor returns the CPAN id for the default author which will be "LOCAL" if you did not provide an alternative param to the the "new" constructor. add # Add a file to the constructor/default author $cpan->add( file => 'any/arbitrary/Perl-Tarball-1.01.tar.gz' ); The "add" method takes a Perl distribution tarball from an arbitrary path, and adds it to the sources path. The specific location the tarball is copied to will be in the root directory for the author provided to the constructor. Returns the install_path value as a convenience, or throws an exception on error. remove # Remove a distribution from the repository $cpan->remove( dist => 'LOCAL/Perl-Tarball-1.01.tar.gz' ); The "remove" method takes a distribution path and removes it from the sources path. The file is also removed. Does not return anything useful and throws an exception on error. author_subpath # $path = 'authors/id/L/LO/LOCAL' $path = $cpan->author_subpath; The "author_subpath" method takes a CPAN author id (or uses the CPAN author id originally provided to the constructor) and returns the relative subpath for the AUTHOR within the sources tree. Returns the subpath as a string. author_path # $path = '/root/.cpan/sources/authors/id/L/LO/LOCAL' $path = $cpan->author_subpath; The "author_path" method finds the full path for the root directory for the named author. Returns the path as a string. file_path # $path = '/root/.cpan/sources/authors/id/L/LO/LOCAL/Perl-Tarball-1.02.tar.gz' $path = $cpan->file_path( 'Perl-Tarball-1.02.tar.gz' ); $path = $cpan->file_path( '/some/random/place/Perl-Tarball-1.02.tar.gz' ); The "file_path" method takes the name of a tarball (either just the name or a full path) and calculates the location that the file will end up at. When files are copied into the sources directory, they are always copied to the top level of the author root. Returns the path as a string. install_path # $path = 'LOCAL/Perl-Tarball-1.01.tar.gz'; $path = $cpan->install_path( 'Perl-Tarball-1.01.tar.gz' ); $path = $cpan->install_path( '/some/random/place/Perl-Tarball-1.02.tar.gz' ); The "install_path" method returns the path for the distribution as the CPAN shell understands it. Using this path, the CPAN shell can expand it to locate the distribution, and then can install it. Returns the path as a string. SUPPORT
This module is stored in an Open Repository at the following address. <http://svn.ali.as/cpan/trunk/CPAN-Inject> Write access to the repository is made available automatically to any published CPAN author, and to most other volunteers on request. If you are able to submit your bug report in the form of new (failing) unit tests, or can apply your fix directly instead of submitting a patch, you are strongly encouraged to do so as the author currently maintains over 100 modules and it can take some time to deal with non- Critcal bug reports or patches. This will guarentee that your issue will be addressed in the next release of the module. If you cannot provide a direct test or fix, or don't have time to do so, then regular bug reports are still accepted and appreciated via the CPAN bug tracker. <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=CPAN-Inject> For other issues, for commercial enhancement or support, or to have your write access enabled for the repository, contact the author at the email address above. AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
CPAN::Mini::Inject COPYRIGHT
Copyright 2006 - 2011 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.10.1 2011-01-05 CPAN::Inject(3pm)
All times are GMT -4. The time now is 01:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy