LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to parse in korn shell (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-parse-in-korn-shell-636362/)

eddieboo 04-18-2008 10:28 PM

How to parse in korn shell
 
Guys, I am having a problem, I have been using ksh script on my aix 52 that parse from the line and give me the file name but but when i try to use the same script on 5.3 it failed to parse,

here is my script line and sample output

InterfaceFile=/law/t803/law/test/interface/smsptrf/rfdc0xk_0418152945
HDR_MASK=/law/test/law/test/interface/smsptrf/

FileName=${InterfaceFile##${HDR_MASK}}

echo $FileName

output should be "rfdc0xk_0418152945" but it is showing me the whole line
/law/t803/law/test/interface/smsptrf/rfdc0xk_0418152945


any idea how can i fix or if there is any other way to get the same result please help me

eddie

tronayne 04-19-2008 07:06 AM

What you're trying to do is parameter expansion - substrings (yeah, yet another strange name for something). The general form is
Code:

${parameter#pattern} remove small left pattern
${parameter##pattern} remove large left pattern
${parameter%pattern} remove small right pattern
${parameter%%pattern} remove large right pattern

So,
Code:

InterfacFile=/law/t803/law/test/interface/smsptrf/rfdc0xk_0418152945
print ${InterfacFile##*/}

Produces
Code:

rfdc0xk_0418152945
The trick is the "##*/"

Hope this helps


All times are GMT -5. The time now is 10:12 AM.