LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-18-2008, 10:28 PM   #1
eddieboo
LQ Newbie
 
Registered: Apr 2008
Posts: 1

Rep: Reputation: 0
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
 
Old 04-19-2008, 07:06 AM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
korn shell: scripting an or for if..then Harry Seldon Linux - General 2 01-10-2008 04:21 PM
Globbing using Korn Shell metallica1973 Programming 1 12-05-2007 04:56 PM
Korn shell and Arrays jpc82 Programming 1 06-28-2005 02:27 AM
install korn shell namgor Linux - Newbie 1 07-12-2004 02:52 PM
a t&t korn shell 93 shook Linux - Software 4 02-01-2003 01:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration