Re: splitting words into individual characters
Chris F.A. Johnson wrote:
> On 2006-11-03, Mitch wrote:
>> Hello again.
>>
>> I'm still learning, but a lot of it I am finding through reading the
>> groups and by asking Google nicely, however I have yet to find an answer
>> to this one.
>>
>> I am trying to break a word down into individual characters. OK that's
>> not true, I'm trying to break down the file permissions into individual
>> sections.
>>
>> I've got ls -l filename | awk ' { print $1 } ' which works (I worked
>> this out myself, so if there is an easier/better way of getting it, I'd
>> appreciate it...) Its giving me what I think I want (-rw-r--r--) but I
>> am trying to figure out how to break it down into individual letters. I
>> have seen examples of "case in (?r*)" format but this would leave me
>> with a lot of variations to consider when I am trying to translate the
>> file permission string into a pretty table.
>>
>> so my question is, how can I change a word (-rw-r--r-- or equiv) into a
>> list/array of individual characters.
>
> set -- $( ls -l "$filename" | sed -e 's/ .*//' -e 's/./& /g' )
>
>
Thanks, though I haven't had a chance to look at sed past simple
s/old/new yet. I know what -e does but have yet to read up on the
special characters. I know that & matches the found sample... I tried to
get this to work but just had no luck with it as is. the set --, does
this mean something I haven't come across yet because it gives errors if
I stick it in the command line. in fact if I include anything other than
ls -l "$filename" | sed -e 's/ .*//' -e 's/./& /g' I get errors. That
said, without the other bits works a treat,so thank you. I was just
curious why the outer parts were added.
Thanks!
Mitch.
|