For Programmers: Free Programming Magazines  


Home > Archive > AWK > December 2005 > [OT] shell question (Re: Splitting a srting at the last occurance









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [OT] shell question (Re: Splitting a srting at the last occurance
Janis Papanagnou

2005-12-03, 7:55 am

Rob Bradford wrote:
> All.
>
> I need to seperate the path from the file name - extension in a shell
> script.


Wrong newsgroup, this is a shell question, use comp.unix.shell instead.

> So far I have ${0%.*} to give me the file name and path, and
> ${0#*.} me the extension.


Both are wrong if you want a split at the path delimiter / and not at
the extension . (dot). Use

${0##*/} for the directory path and
${0%/*} for the program name


Janis


> Depending on how I call the script (test.sh) the first of the above
> either
>
> ./test
>
> or
>
> /home/scripts/test
>
> what I now need to do is split it into two
>
> ./ or /home/scripts
>
> and
>
> test
>
> Just catching the last four characters is not the answer as I am trying
> to make this generic, e.g The ccript name could be "slilyscript.scr" in
> such a case I wold just want the "sillyscript" bit seperated from it's
> path.
>
>
> May be AWK is not the way I don't know, any help or pointers
> appreciated.
>
> Robert

Janis Papanagnou

2005-12-03, 7:55 am

Rob Bradford wrote:
> Janis Papanagnou wrote on 03/12/2005 in comp.lang.awk:
>
> I did say I wasn't sure if this was an AWK thing or not. I'll repost in
> a shell group.


I gave you the information about the shell newsgroup because you
don't seem to have been aware of its existance.

The two patterns I gave you above will already solve your task.

Janis
Janis Papanagnou

2005-12-03, 7:55 am

Rob Bradford wrote:

I read your posting as if the above was the only you want to achieve.
[color=darkred]
> I knew about the group, I just felt this was an AWK issue as I wanted
> the program name minus extension i.e "test" from /home/scripts/test.sh
> as this involved loosing stuff at both ends of the sting I directed it
> at the AWK group as I felt that was twhere it belonged.
>
> I'm trying to genericly split the name of a script $0 into three parts
>
> i The path
> ii The extension
> iii The filename minus extension.
>
> I've got i and ii but can't get iii.


See my reply to your posting in comp.unix.shell how to obtain iii.

Janis
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com