Kaushal Shriyan | 2 Dec 12:00 2009
Picon

directory exists

Hi,

I have binary files 20080630 under a particular directory
(/mnt/data1/adserver/BinaryAdLogs) and there is a directory by the
name 2008_6_30 in /mnt/data1/adserver/DailyLogs

Basically i need to check the directory whether it exists in
/mnt/data1/adserver/DailyLogs for all the binary files located in
/mnt/data1/adserver/BinaryAdLogs

Please suggest/guide.

Thanks,

Kaushal
Roger | 2 Dec 19:49 2009
Picon

Re: directory exists

On Wed, Dec 2, 2009 at 3:00 AM, Kaushal Shriyan
<kaushalshriyan@...> wrote:
> Hi,
>
> I have binary files 20080630 under a particular directory
> (/mnt/data1/adserver/BinaryAdLogs) and there is a directory by the
> name 2008_6_30 in /mnt/data1/adserver/DailyLogs
Does it always drop the leading 0 for month?  (assuming that's
Year_month_day).   Does it drop leading zero for the day, ie, if it's
20080609, does it go to 2008_6_9 ?

> Basically i need to check the directory whether it exists in
> /mnt/data1/adserver/DailyLogs for all the binary files located in
> /mnt/data1/adserver/BinaryAdLogs

Grab the list of files, alter the name, then look for that directory.
  If there were no mutation of the file name, it could easily be a
shell script.    I'd probably use perl, but that's just me.

> Please suggest/guide.
>
> Thanks,
>
> Kaushal
> _______________________________________________
> Shell.Scripting mailing list
> Shell.Scripting@...
> http://www2.codegnome.org:59321/cgi-bin/mailman/listinfo/shell.scripting
>
(Continue reading)

Kaushal Shriyan | 3 Dec 05:53 2009
Picon

Re: directory exists

On Thu, Dec 3, 2009 at 12:19 AM, Roger <roger.in.eugene@...> wrote:
> On Wed, Dec 2, 2009 at 3:00 AM, Kaushal Shriyan
> <kaushalshriyan@...> wrote:
>> Hi,
>>
>> I have binary files 20080630 under a particular directory
>> (/mnt/data1/adserver/BinaryAdLogs) and there is a directory by the
>> name 2008_6_30 in /mnt/data1/adserver/DailyLogs
> Does it always drop the leading 0 for month?  (assuming that's
> Year_month_day).   Does it drop leading zero for the day, ie, if it's
> 20080609, does it go to 2008_6_9 ?

yes, I have this directory too ---> 2008_6_9

>
>> Basically i need to check the directory whether it exists in
>> /mnt/data1/adserver/DailyLogs for all the binary files located in
>> /mnt/data1/adserver/BinaryAdLogs
>
> Grab the list of files, alter the name, then look for that directory.
>  If there were no mutation of the file name, it could easily be a
> shell script.    I'd probably use perl, but that's just me.

Any snippet of code ?

Thanks,

Kaushal
Kaushal Shriyan | 3 Dec 06:20 2009
Picon

Parameter Expansion

Hi,

Can someone explain me about Parameter Expansion in BASH ? Its really
difficult to grasp.

Thanks,

Kaushal
Roger | 3 Dec 07:41 2009
Picon

Re: directory exists

kind of ugly:

 <at> filelist=`ls`;
while($file=shift( <at> filelist)){
chomp($file);
$part1=substr($file,0,4);
$part2=substr($file,4,2);
$part2=~ s/^0//;
$part3=substr($file,6,2);
$part3=~ s/^0//;
$dir=$part1."_".$part2."_".$part3;
if(-d "../testdir/$dir" ){
print $dir;
}
}

On Wed, Dec 2, 2009 at 8:53 PM, Kaushal Shriyan
<kaushalshriyan@...> wrote:
> On Thu, Dec 3, 2009 at 12:19 AM, Roger <roger.in.eugene@...> wrote:
>> On Wed, Dec 2, 2009 at 3:00 AM, Kaushal Shriyan
>> <kaushalshriyan@...> wrote:
>>> Hi,
>>>
>>> I have binary files 20080630 under a particular directory
>>> (/mnt/data1/adserver/BinaryAdLogs) and there is a directory by the
>>> name 2008_6_30 in /mnt/data1/adserver/DailyLogs
>> Does it always drop the leading 0 for month?  (assuming that's
>> Year_month_day).   Does it drop leading zero for the day, ie, if it's
>> 20080609, does it go to 2008_6_9 ?
>
(Continue reading)

Roger | 3 Dec 08:06 2009
Picon

Re: Parameter Expansion

On Wed, Dec 2, 2009 at 9:20 PM, Kaushal Shriyan
<kaushalshriyan@...> wrote:
> Hi,
>
> Can someone explain me about Parameter Expansion in BASH ? Its really
> difficult to grasp.

I have troubles with that too.

One form of parameter expansion,   ${parameter%%word}
works like this,
#!/bin/bash
ONE=${1%%blah}
echo $ONE

It checks the first parameter you give it, if it ends in the word
BLAH, then it removes that word from the string and assigns it to the
variable $ONE.    If it does not end in BLAH, then it assigns the
entire string to the variable $ONE

${1##BLAH}
would do the same thing, but at the beginning of the string.

I used the %% form several years ago to convert latitude from  35.04S
to -35.04 and W latitudes to - numbers.

Roger
Todd A. Jacobs | 3 Dec 16:04 2009

Re: Parameter Expansion

On Thu, Dec 03, 2009 at 10:50:19AM +0530, Kaushal Shriyan wrote:

> Can someone explain me about Parameter Expansion in BASH ? Its really
> difficult to grasp.

If you can provide an example of what you're trying to do, we can help
you figure out what kind of expansion you need and why.

--

-- 
"Oh, look: rocks!"
	-- Doctor Who, "Destiny of the Daleks"
Kaushal Shriyan | 3 Dec 18:06 2009
Picon

Re: Parameter Expansion

On Thu, Dec 3, 2009 at 8:34 PM, Todd A. Jacobs <nospam@...> wrote:
> On Thu, Dec 03, 2009 at 10:50:19AM +0530, Kaushal Shriyan wrote:
>
>> Can someone explain me about Parameter Expansion in BASH ? Its really
>> difficult to grasp.
>
> If you can provide an example of what you're trying to do, we can help
> you figure out what kind of expansion you need and why.
>

Hi Todd,

I am learning shell scripting as suggested by you after going through
oreilly books(Learning the Bash Shell).
I could not proceed from there.

Please guide.

Thanks,

Kaushal
Todd A. Jacobs | 3 Dec 20:43 2009

Re: Parameter Expansion

On Thu, Dec 03, 2009 at 10:36:27PM +0530, Kaushal Shriyan wrote:

> I could not proceed from there.

The bash manual is a little terse, but fairly thorough:

    http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion

on the subject of parameter expansion. Think of parameter expansions as
transformations of the values of a variable, and it might make more
sense. In the manual, "parameter" means a variable name, while "word"
means the value to substitute for whatever is currently held in the
variable.

So, "echo ${foo:-bar}" will either print the value of $foo, or print
"bar" if $foo is unset. This is the expansion I use most, as it's a
great way to set default values for things, and it has the side-effect
of giving you a value while still leaving $foo unset.

You don't really need them, though. They are convenience functions. You
could accomplish the same thing with:

    if [[ -n $foo ]]; then
	foo="bar"
    fi

or:

    test -n "$foo" || foo="bar"

(Continue reading)

Cameron Simpson | 4 Dec 03:07 2009
Picon
Picon

Re: Parameter Expansion

On 03Dec2009 11:43, Todd A. Jacobs <nospam@...> wrote:
| On Thu, Dec 03, 2009 at 10:36:27PM +0530, Kaushal Shriyan wrote:
| > I could not proceed from there.
| 
| The bash manual is a little terse, but fairly thorough:
| 
|     http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion
| 
| on the subject of parameter expansion. Think of parameter expansions as
| transformations of the values of a variable, and it might make more
| sense. In the manual, "parameter" means a variable name, while "word"
| means the value to substitute for whatever is currently held in the
| variable.
| 
| So, "echo ${foo:-bar}" will either print the value of $foo, or print
| "bar" if $foo is unset. This is the expansion I use most, as it's a
| great way to set default values for things, and it has the side-effect
| of giving you a value while still leaving $foo unset.
| 
| You don't really need them, though. They are convenience functions. You
| could accomplish the same thing with:
| 
|     if [[ -n $foo ]]; then
| 	foo="bar"
|     fi
| 
| or:
| 
|     test -n "$foo" || foo="bar"
| 
(Continue reading)


Gmane