Sponsored Content
Top Forums Shell Programming and Scripting For loop and read from different directories Post 303001156 by rovf on Friday 28th of July 2017 02:37:33 AM
Old 07-28-2017
Let's line out the basic idea:

I would first read the content of each directory into a separate array, in this case 3 arrays (A, B, C). Then I would set up an associative array (let's call it SEEN), where I enter the basename from each file which has already been processed. Checking SEEN before processing a file allows me to skip the files which have already been processed. I then would have a single loop, ranging over the indexes of the longest array. Inside the loop, I would use the loop index to access the arrays A, B and C.

One design decision is, whether the number of directories is always constant (3) or can be variable too. If there is no inherent necessity, why it must be 3 directories, and not 2 or 4, I would make this variable too.

Now it comes for choosing the programming language. You need a language which supports arrays and associative arrays. For shell scripting, it means that you can use Zsh or bash or - I think - ksh.

If you decided to make the number of directories a variable too, you **can** do it in shell scripts, but I find it a bit invonvenient. For this type of task, I would consider a more general programming language, such as Ruby or Perl.
This User Gave Thanks to rovf For This Post:
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to loop through all files and directories.

I'm trying to write a script that will loop through all files and directories down from a path I give it, and change the permissions and ACL. I was able to do the obvious way and change the files and folders on the same level as teh path...but I need it to continue on deeper into the file... (2 Replies)
Discussion started by: cheetobandito
2 Replies

2. Shell Programming and Scripting

How to loop through directories to touch files

Hi, Please help me on this. Suppose i have the following directory structure. /app/data /app/data/eng /app/data/med /app/data/bsc each of the directories data,data/eng,data/med,data/bsc holds files with date extension like a.20081230 b.20081230 and so on I need a script to loop... (9 Replies)
Discussion started by: sussane
9 Replies

3. Shell Programming and Scripting

Newbie: How to loop round sub-directories

I want a bit of shell script that will let me loop round all the sub-directories in a directory (i.e. ignoring any ordinary files in that directory). Let's say I just want to echo the names of the sub-directories. This sounds like it should be pretty easy - but not for me, it isn't! All help... (4 Replies)
Discussion started by: cjhancock
4 Replies

4. Shell Programming and Scripting

Loop to move files in different directories

Hi, I have various log files in different paths. e.g. a/b/c/d/e/server.log a/b/c/d/f/server.log a/b/c/d/g/server.log a/b/c/h/e/server.log a/b/c/h/f/server.log a/b/c/h/g/server.log a/b/c/i/e/server.log a/b/c/i/e/server.log a/b/c/i/e/server.log and above these have an archive folder... (6 Replies)
Discussion started by: acc01
6 Replies

5. Shell Programming and Scripting

For Loop Range Create Directories

Hello, I am a bit stumped on this. I am attempting to create 24 empty directories with a loop. Seems like I have incorrect syntax. When I run the following command I get the error below. Command $ for i in {2..24}; do mkdir $i_MAY_2011 ; doneError x 24 mkdir: missing operand Try `mkdir... (2 Replies)
Discussion started by: jaysunn
2 Replies

6. Shell Programming and Scripting

To read directories and file

Hi ; I want to write a shell script to read all files and directories(recursively) given in path along with their user permissions and store that result in one file as File path Userpermissions ===== =========== I m new to linux and my dont kno much abt shell scripting. I will... (5 Replies)
Discussion started by: ajaypadvi
5 Replies

7. UNIX for Dummies Questions & Answers

Read statement within while read loop

hi, this is my script #!/bin/ksh cat temp_file.dat | while read line do read test if ]; then break else echo "ERROR" fi done when i execute this code , the script does wait for the user input . it directly prints "ERROR" and terminates after the no. of times as there... (3 Replies)
Discussion started by: siva1612
3 Replies

8. Shell Programming and Scripting

Accessing multiple directories in loop

Hi Guys, I need to access multiple directories whcih is following similar structure and need to copy those files in desitination path. for eg : if ] then cd ${DIR}/Mon/loaded echo "copying files to $GRS_DIR" cp * ${DIR}/Mon/ echo "Files of Monday are Copied" fi if ] then... (5 Replies)
Discussion started by: rohit_shinez
5 Replies

9. Solaris

Giving read write permission to user for specific directories and sub directories.

I have searched this quite a long time but couldn't find the right method for me to use. I need to assign read write permission to the user for specific directories and it's sub directories and files. I do not want to use ACL. This is for Solaris. Please help. (1 Reply)
Discussion started by: blinkingdan
1 Replies
Font::TTF::Name(3pm)					User Contributed Perl Documentation				      Font::TTF::Name(3pm)

NAME
Font::TTF::Name - String table for a TTF font DESCRIPTION
Strings are held by number, platform, encoding and language. Strings are accessed as: $f->{'name'}{'strings'}[$number][$platform_id][$encoding_id]{$language_id} Notice that the language is held in an associative array due to its sparse nature on some platforms such as Microsoft ($pid = 3). Notice also that the array order is different from the stored array order (platform, encoding, language, number) to allow for easy manipulation of strings by number (which is what I guess most people will want to do). By default, $Font::TTF::Name::utf8 is set to 1, and strings will be stored as UTF8 wherever possible. The method "is_utf8" can be used to find out if a string in a particular platform and encoding will be returned as UTF8. Unicode strings are always converted if utf8 is requested. Otherwise, strings are stored according to platform: You now have to set <$Font::TTF::Name::utf8> to 0 to get the old behaviour. Apple Unicode (platform id = 0) Data is stored as network ordered UCS2. There is no encoding id for this platform but there are language ids as per Mac language ids. Mac (platform id = 1) Data is stored as 8-bit binary data, leaving the interpretation to the user according to encoding id. Unicode (platform id = 2) Currently stored as 16-bit network ordered UCS2. Upon release of Perl 5.005 this will change to utf8 assuming current UCS2 semantics for all encoding ids. Windows (platform id = 3) As per Unicode, the data is currently stored as 16-bit network ordered UCS2. Upon release of Perl 5.005 this will change to utf8 assuming current UCS2 semantics for all encoding ids. INSTANCE VARIABLES
strings An array of arrays, etc. METHODS
$t->read Reads all the names into memory $t->out($fh) Writes out all the strings $t->XML_element($context, $depth, $key, $value) Outputs the string element in nice XML (which is all the table really!) $t->XML_end($context, $tag, %attrs) Store strings in the right place is_utf8($pid, $eid) Returns whether a string of a given platform and encoding is going to be in UTF8 find_name($nid) Hunts down a name in all the standard places and returns the string and for an array context the pid, eid & lid as well set_name($nid, $str[, $lang[, @cover]]) Sets the given name id string to $str for all platforms and encodings that this module can handle. If $lang is set, it is interpretted as a language tag and if the particular language of a string is found to match, then that string is changed, otherwise no change occurs. If supplied, @cover should be a list of references to two-element arrays containing pid,eid pairs that should be added to the name table if not already present. This function does not add any names to the table unless @cover is supplied. Font::TTF::Name->match_lang($pid, $lid, $lang) Compares the language associated to the string of given platform and language with the given language tag. If the language matches the tag (i.e. is equal or more defined than the given language tag) returns true. This is calculated by finding whether the associated language tag starts with the given language tag. Font::TTF::Name->get_lang($pid, $lid) Returns the language tag associated with a particular platform and language id Font::TTF::Name->find_lang($pid, $lang) Looks up the language name and returns a lang id if one exists BUGS
o Unicode type strings will be stored in utf8 for all known platforms, once Perl 5.6 has been released and I can find all the mapping tables, etc. AUTHOR
Martin Hosken Martin_Hosken@sil.org. See Font::TTF::Font for copyright and licensing. perl v5.10.1 2010-10-28 Font::TTF::Name(3pm)
All times are GMT -4. The time now is 01:17 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy