What language to manipulate text files

R

rossnixon

I want to do some tricky text file manipulation, but have only a little
programming knowledge.

What are the ideal languages for the following examples?

1. Starting from a certain folder, look in the subfolders for all
filenames matching *FOOD*.txt Any files matching in each folder should
be copied to a new subfolder of the current folder called EATING with a
new name of *FOOD*COPY.txt

2. Process each file as follows:
Here is a simplified example of what I want to start from and end up
with.

------------------------------------- input
.......................... 'several unknown lines of text file
Get apples from apples shop
Get oranges from oranges shop
Get plums from plums shop
Get pears from pears shop
Eat from apples, oranges,
plums, pears 'whitespace at start of line is unimportant
.......................... 'more unknown lines of text file
Chapter 1
Several lines of text about apples in here
Chapter 2
Several lines of text about oranges in here
Chapter 3
Several lines of text about plums in here
Chapter 4
Several lines of text about pears in here

------------------------------------- output
.......................... 'several unknown lines of text file
Get apples from apples shop
Get oranges from oranges shop
Get plums from plums shop
Get pears from pears shop
Get bagels from bagels shop 'the Get lines...
Get donuts from donuts shop 'can be in any order
Eat from apples, bagels, oranges,
plums, donuts, pears 'whitespace at start of line is unimportant
.......................... 'more unknown lines of text file
Chapter 1
Several lines of text about apples in here
Chapter 2
Several lines of text about bagels in here
Chapter 3
Several lines of text about oranges in here
Chapter 4
Several lines of text about plums in here
Chapter 5
Several lines of text about donuts in here
Chapter 6
Several lines of text about pears in here

Summary:
I have added two new items to Get.
I have put them into the comma-delimited list after searching for a
particular fruit that each one should follow.
The chapters are renumbered to match their position in the
comma-delimited list.
The "several lines of text" about each new item can be pulled from a
new_foods.txt file (or a bagels.txt and a donuts.txt file).

My first objective is to process the files as described.
My second objective is to learn the best language for this sort of text
manipulation.
The language should run on Windows 98, XP and Linux.
Would Python be best, or would a macro-scripting thing like AutoHotKey
work?
I thought about learning perl, but wonder about the learning curve and
the maintainability of the code.

Thanks, Ross
 
R

RedGrittyBrick

I want to do some tricky text file manipulation, but have only a little
programming knowledge.

What are the ideal languages for the following examples?

Since you posted this to a Perl newsgroup you probably know what kind of
answer to expect. No language is ideal of course.
1. Starting from a certain folder, look in the subfolders for all
filenames matching *FOOD*.txt Any files matching in each folder should
be copied to a new subfolder of the current folder called EATING with a
new name of *FOOD*COPY.txt

I'd do this as a shell command using find.
2. Process each file as follows:
Here is a simplified example of what I want to start from and end up
with.

------------------------------------- input
......................... 'several unknown lines of text file
Get apples from apples shop
Get oranges from oranges shop
Get plums from plums shop
Get pears from pears shop
Eat from apples, oranges,
plums, pears 'whitespace at start of line is unimportant
......................... 'more unknown lines of text file
Chapter 1
Several lines of text about apples in here
Chapter 2
Several lines of text about oranges in here
Chapter 3
Several lines of text about plums in here
Chapter 4
Several lines of text about pears in here

------------------------------------- output
......................... 'several unknown lines of text file
Get apples from apples shop
Get oranges from oranges shop
Get plums from plums shop
Get pears from pears shop
Get bagels from bagels shop 'the Get lines...
Get donuts from donuts shop 'can be in any order
Eat from apples, bagels, oranges,
plums, donuts, pears 'whitespace at start of line is unimportant
......................... 'more unknown lines of text file
Chapter 1
Several lines of text about apples in here
Chapter 2
Several lines of text about bagels in here
Chapter 3
Several lines of text about oranges in here
Chapter 4
Several lines of text about plums in here
Chapter 5
Several lines of text about donuts in here
Chapter 6
Several lines of text about pears in here

Summary:
I have added two new items to Get.
I have put them into the comma-delimited list after searching for a
particular fruit that each one should follow.
The chapters are renumbered to match their position in the
comma-delimited list.
The "several lines of text" about each new item can be pulled from a
new_foods.txt file (or a bagels.txt and a donuts.txt file).

I'd be happy to use Perl for that and would expect it to be relatively
simple.
My first objective is to process the files as described.

Isn't that best achieved either by using a language you already know or
paying someone experienced to write a program for you?
My second objective is to learn the best language for this sort of text
manipulation.

Do you mean
a) Be told what is best then learn it.
b) Learn for yourself which is best.

If the latter, you'll need to learn all computer languages, implement a
solution in each, repeat for a decade or so and then come to a view.

Frankly I don't think its worth the effort. Just pick a language that is
close to something you know.
The language should run on Windows 98, XP and Linux.

Most popular languages do. Perl included.
Would Python be best, or would a macro-scripting thing like AutoHotKey
work?

I'd pick a programming language not a macro scripting tool.
I thought about learning perl, but wonder about the learning curve and
the maintainability of the code.

I'd say learning curve and maintainability depend more on your
characteristics than on the characteristic of Perl.

IMHO Perl is usable for the tasks you mention even with only a
rudimentary knowledge of Perl. After learning more than rudimentary perl
you would typically be able to rewrite a working program to be more
concise, elegant and faster.

Maintainability depends on lots of things that are language independant.
I find that how maintainable a perl program is, depends almost
entirely on how it was written (indentation, structure, comments,
modules, algorithms and so on.) If you can write maintainable programs
in any other language you'll be able to in Perl.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,586
Members
45,088
Latest member
JeremyMedl

Latest Threads

Top