![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Looping on a list of files... | lazerfoursix | Shell Programming and Scripting | 23 | 04-09-2007 06:18 AM |
| Looping/Repetition in Batch files | kimpot7268 | Shell Programming and Scripting | 2 | 12-12-2005 05:45 AM |
| Looping/Repetition in Batch files | kimpot7268 | UNIX for Advanced & Expert Users | 1 | 12-10-2005 01:49 AM |
| Help looping through files, please... | kapolani | Shell Programming and Scripting | 2 | 10-27-2004 10:28 AM |
| looping files | dharmesht | Shell Programming and Scripting | 5 | 12-03-2003 03:36 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Looping through files...
I posted this in the Solaris forum, but I don't think it's platform specific, so I'm posting it here.
Here is the situation. We are a company that has been using a professional publishing system, the software is called "ProType". It runs on Solaris 2.4, however it is no longer supported and we are forced to move on to Adobe Indesign. We must convert all our documents (thousands) to InDesign format. ProType comes with an export utility that exports the text to ASCII with all the formatting etc. The problem is that the export process takes some time for each file. It is taking a VERY long time to export these documents. How difficult would it be to loop through the documents in a folder and export them? This is the exact process if I were doing it manually: 1) Type: cd /bedford6:/export 2) Then I would type the directory of where the files I want to export are, for example cd /home/mesorah/layout 3) Then I would type: expage P Pg001 > Pg001 where "P Pg001" would be the name of the current file and "Pg001" would be then name of the exported file (the exported file needs to drop the first P). Could this be automated with a script to loop through every document in a directory while making sure to leave out the P when typing the exported page? Last edited by Fred Goldman; 11-07-2007 at 02:59 PM. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I don't see the point of running the "cd" command twice in a row, unless the "expage" program is using $OLDPWD.
Since you say there are thousands of documents, the loop "for i in *" trick is probably a bad idea. Ditto on the spaces in the filenames (I assume "P Pg001" is a filename?). So: Code:
ls | while read FILE; do
NEWFILE=${LINE##* }
echo $(date +%H:%M) expage "$FILE" \> "$NEWFILE"
expage "$FILE" > "$NEWFILE"
done
If it isn't obvious: You should test this in a directory with a few files that are backed up somewhere until you're comfortable that this works the way you think it does. |
|
#3
|
|||
|
|||
|
OK, I am going to try this tomorrow...
The P before the file name is the way ProType recognizes its files like a file extension of some sort (I apologize I know very little about UNIX). I need the export utility to keep the same file name except for the P. I don't quite understand what you mean by removing the spaces. Do you mean you are going to first rename the files without the spaces? The way these files are set up is there are about 10-30 files in each directory with about 100 or so directories. I planned on running the script on each directory individually. Ok (if I haven't until now I am really going to show off my ignorance) how do I call this script. |
|
#4
|
|||
|
|||
|
OK, this is the exact script I am running, I just get a "command not found". Any ideas?
Code:
#!/bin/tcsh
ls | while read FILE; do
NEWFILE=${LINE##* }
echo $(date +%H:%M) expage "$FILE" \> "$NEWFILE"
expage "$FILE" > "$NEWFILE"
done
|
|
#5
|
|||
|
|||
|
Hmmm, "tcsh"? Eeeek. I'm not really familiar with that shell. Try:
#!/bin/ksh #!/bin/zsh #!/bin/bash #!/bin/sh Not necessarily in that order. |
|
#6
|
|||
|
|||
|
OK, I think we are getting somewhere.
With ksh I got syntax error line 7 done unexpected With sh I got syntax error line 4 ( unexpected. |
|
#7
|
|||
|
|||
|
OK, Ive done a little research and this should be the syntax for tcsh:
Code:
#!/usr/bin/env tcsh foreach file ($*) set newname="$file.txt" export "$file" /> "$newname" end |
|||
| Google The UNIX and Linux Forums |