Re: How to get all of parent path (including itself) for a specified path on Linux or how to get all of substring (including itself) for a string on Oracle SQL?

From: Quanwen Zhao <quanwenzhao_at_gmail.com>
Date: Tue, 21 Mar 2023 10:22:20 +0800
Message-ID: <CABpiuuQ_BPPRQxhCnQFbtZBb=tOkkWJrSSq8tA3oExKtUiC-yQ_at_mail.gmail.com>



Hi Ghassan, Maxim and Mladen :-),

The solution for sql and shell bomb don't seem like to include "/".

The perl script here I reported an error.

[oracle_at_demo50 ~]$
> [oracle_at_demo50 ~]$ cat /tmp/ttt
> !/usr/bin/perl
> my _at_MD=split ('/',$ARGV[0]);
> my $output='';
> foreach (_at_MD) {
> $output .= "/$_";
> $output=~s/\/\//\//;
> print "$output\n";
> }
> [oracle_at_demo50 ~]$
> [oracle_at_demo50 ~]$ ls -lrht /tmp/ttt
> -rwxr-xr-x 1 oracle oinstall 148 Mar 21 10:15 /tmp/ttt
> [oracle_at_demo50 ~]$
> [oracle_at_demo50 ~]$
> [oracle_at_demo50 ~]$
> [oracle_at_demo50 ~]$ /tmp/ttt '/oracle/base/product/19c/dbhome_1'
> /tmp/ttt: line 1: !/usr/bin/perl: No such file or directory
> /tmp/ttt: line 2: syntax error near unexpected token `('
> /tmp/ttt: line 2: `my _at_MD=split ('/',$ARGV[0]);'
> [oracle_at_demo50 ~]$

Best Regards
Quanwen Zhao

Quanwen Zhao <quanwenzhao_at_gmail.com> 于2023年3月14日周二 09:38写道:

> Thanks to everyone for giving me the very nice solution. I'll try it
> later. 🙏🤘😊.

>

> Ghassan Salem <salem.ghassan_at_gmail.com> 于2023年3月13日周一 23:20写道:
>
>> In sql
>> select nvl(substr(paths,1, instr(paths,'/',1,level+1)-1),paths)
>> from (select '/oracle/base/product/19c/dbhome_1' paths from dual)
>> connect by level<=regexp_count(paths,'/') ;
>> (gives the same output)
>>
>> On Mon, Mar 13, 2023 at 4:15 PM Maxim <mdemenko_at_gmail.com> wrote:
>>
>>> variation of the bash fork bomb ;-)
>>>
>>>  :() { [[ ! -z $1 ]] && echo $1 &&  :  ${1%/*};  } ; :
>>> /oracle/base/product/19c/dbhome_1|sort
>>> /oracle
>>> /oracle/base
>>> /oracle/base/product
>>> /oracle/base/product/19c
>>> /oracle/base/product/19c/dbhome_1
>>>
>>> Regards
>>>
>>> Maxim
>>>
>>> On Mon, Mar 13, 2023 at 3:28 PM Mladen Gogala <gogala.mladen_at_gmail.com>
>>> wrote:
>>>
>>>> On 3/13/23 01:49, Quanwen Zhao wrote:
>>>>
>>>> Hello listeners :-),
>>>>
>>>> I've an requirement getting all of parent path (including itself) for a
>>>> specified path on Linux or getting all of substring (including itself) for
>>>> a string on Oracle SQL?
>>>>
>>>> such as, the path is "/home/oracle/arch", the desired output is:
>>>>
>>>> /home/oracle/arch
>>>>> /home/oracle
>>>>> /home
>>>>> /
>>>>
>>>>
>>>>  or I've created a test table.
>>>>
>>>> TEST_at_orcl>create table test1 (arch_loc varchar2(50));
>>>>> Table created.
>>>>
>>>>
>>>> TEST_at_orcl>insert into test1 values ('/home/oracle/arch');
>>>>> 1 row created.
>>>>
>>>>
>>>> TEST_at_orcl>commit;
>>>>> Commit complete.
>>>>
>>>>
>>>> TEST_at_orcl>select * from test1;
>>>>> ARCH_LOC
>>>>> --------------------------------------------------
>>>>> /home/oracle/arch
>>>>
>>>>
>>>> Whatever, using the SHELL or Oracle SQL to get the same output. Please
>>>> help me finish it, thanks beforehand!
>>>>
>>>> Best Regards
>>>> Quanwen Zhao
>>>>
>>>>
>>>> I would use something like this:
>>>>
>>>> !/usr/bin/perl
>>>> my _at_MD=split ('/',$ARGV[0]);
>>>> my $output='';
>>>> foreach  (_at_MD) {
>>>>     $output .= "/$_";
>>>>     $output=~s/\/\//\//;
>>>>     print "$output\n";
>>>> }
>>>>
>>>> This works:
>>>>
>>>> [mgogala_at_umajor scripts]$ /tmp/ttt '/oracle/base/product/19c/dbhome_1'
>>>> /
>>>> /oracle
>>>> /oracle/base
>>>> /oracle/base/product
>>>> /oracle/base/product/19c
>>>> /oracle/base/product/19c/dbhome_1
>>>>
>>>> You can use PL/SQL regex functions to do the same in PL/SQL.
>>>>
>>>> --
>>>> Mladen Gogala
>>>> Database Consultant
>>>> Tel: (347) 321-1217https://dbwhisperer.wordpress.com
>>>>
>>>>

--
http://www.freelists.org/webpage/oracle-l
Received on Tue Mar 21 2023 - 03:22:20 CET

Original text of this message