f



how to get the value?

Hi,

I have a data file like:
conf.dat:
abst0012328$y$m$d.out.asc~e~b~c

In my shell script:
y=2004
m=10
d=14

I got the file name from data file:
filename=abst0012328$y$m$d.out.asc

actually what I really want is:
filename=abst001232820041014.out.asc

How can I get it?

Thanks,
Carl


0
linlin107
10/14/2004 11:05:36 PM
comp.unix.shell 15484 articles. 3 followers. Post Follow

3 Replies
383 Views

Similar Articles

[PageSpeed] 45

On 2004-10-14, linlin107 wrote:
> Hi,
>
> I have a data file like:
> conf.dat:
> abst0012328$y$m$d.out.asc~e~b~c
>
> In my shell script:
> y=2004
> m=10
> d=14
>
> I got the file name from data file:
> filename=abst0012328$y$m$d.out.asc
>
> actually what I really want is:
> filename=abst001232820041014.out.asc

    Assuming a POSIX shell, such as bash or ksh:

filename=${filename%%~*}

    Otherwise:

filename=`echo "$filename" | cut -d~ -f1`

    Or:

filename=`expr  "$filename" : '\([^~]*\).*'`


-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
0
Chris
10/15/2004 1:11:23 AM
   Oops; I didn't read carefully enough, and provided a solution to
   the wrong problem. :(.

   See below for what you wanted.

On 2004-10-15, Chris F.A. Johnson wrote:
> On 2004-10-14, linlin107 wrote:
>> Hi,
>>
>> I have a data file like:
>> conf.dat:
>> abst0012328$y$m$d.out.asc~e~b~c
>>
>> In my shell script:
>> y=2004
>> m=10
>> d=14
>>
>> I got the file name from data file:
>> filename=abst0012328$y$m$d.out.asc
>>
>> actually what I really want is:
>> filename=abst001232820041014.out.asc

eval "filename='$filename'"


-- 
    Chris F.A. Johnson                  http://cfaj.freeshell.org/shell
    ===================================================================
    My code (if any) in this post is copyright 2004, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License
0
Chris
10/15/2004 1:22:25 AM
In article <BIGdnWKa8PbeifLcRVn-uw@rogers.com>,
 "linlin107" <linlin107@rogers.com> wrote:

> Hi,
> 
> I have a data file like:
> conf.dat:
> abst0012328$y$m$d.out.asc~e~b~c
> 
> In my shell script:
> y=2004
> m=10
> d=14
> 
> I got the file name from data file:
> filename=abst0012328$y$m$d.out.asc
> 
> actually what I really want is:
> filename=abst001232820041014.out.asc

What happened to ~e~b~c at the end?

> 
> How can I get it?

eval filename=`cat conf.dat`

and then remove the ~ stuff.

-- 
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
0
Barry
10/15/2004 1:28:39 AM
Reply: