Split Index and File Name from string?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Message
Author
User avatar
Moose On The Loose
Posts: 965
Joined: Thu 24 Feb 2011, 14:54

#21 Post by Moose On The Loose »

technosaurus wrote:
stu91 wrote:
amigo wrote:All these loops and extraneous use of echo, sed and cut... Bash makes this very simple:

Code: Select all

INDEX=${OUTSTR%%-*}
FILENAME=${OUTSTR#*-}
see "substring manipulation" in the advanced bash scripting guide.
Just as a BTW a trick I use fairly often is to make the thing I am working on contain spaces at key points and then do:

Code: Select all

MyFunctionName  $TheStringInQuestion
This way all the bits of the string come into the function as $1 ...

Inside the function I can then do all manner of stuff to the string. This is good when what you want to do is more complex than the example here because it makes it easier to document what is done.

Post Reply