[wplug] Breaking a word into the individual characters in a shell script

Moshe Hyzon mokatz at gmail.com
Tue Aug 19 11:16:35 EDT 2008


Actually, I should try these things before I send them out.  Here's a
version that works:

echo foo| awk --field-separator='' '{print $1 " " $2 " "$3}'
f o o


On Tue, Aug 19, 2008 at 11:08 AM, Moshe Hyzon <mokatz at gmail.com> wrote:
> just set FS to null in the begin block
>
> awk -e 'BEGIN{FS=""}{print
> "path/"$1"/"$2"/"$3"/"$4"/"$5"/"$6"/"$7"/"}' or the like
>
> Moshe
>
>
> On Tue, Aug 19, 2008 at 10:51 AM, Rob Lines <rlinesseagate at gmail.com> wrote:
>> I have dealt with using awk to grab certain columns in a file and then
>> work with them as variables but now I want to take a single word and
>> break it up into the individual characters for example
>>
>> dog and I want to assign d, o and g to separate variables to work
>> with.  I looked through the awk man page and I am just not finding how
>> to interact with the x character that I pass it.
>>
>> I may not be looking at the right tool for the job so if anyone has
>> any suggestions of another tool that would work suggestions are
>> welcome.
>>
>> The end goal is that I have a large number of files that need to be
>> sorted into directories based on the name of the files (that I already
>> have) and those directories are all based on the name of the file.
>> for example the file dogncat_0321 would be found in
>> /path/d/o/g/n/c/a/t/.  I want to pass the filename to the command and
>> have it grab the first 7 characters (and always the first 7
>> characters) and save each one in a seperate variable as the directory
>> structure may or may not currently exist and I plan to check for the
>> existence in the script and generate it on the fly if it is not
>> already there.
>>
>> Thanks for any help or pointers in the right direction.
>>
>> Rob
>> _______________________________________________
>> wplug mailing list
>> wplug at wplug.org
>> http://www.wplug.org/mailman/listinfo/wplug
>>
>


More information about the wplug mailing list