The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-07-2007
Registered User
 

Join Date: Nov 2007
Posts: 14
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.
Reply With Quote
Forum Sponsor
  #2  
Old 11-07-2007
Registered User
 

Join Date: Oct 2007
Posts: 155
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
The form "${LINE##* }" should remove everything up to and including the last space from the left. It would seem to be necessary to quote "$LINE" when running expage, if the filename really has embedded spaces.

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.
Reply With Quote
  #3  
Old 11-07-2007
Registered User
 

Join Date: Nov 2007
Posts: 14
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.
Reply With Quote
  #4  
Old 11-08-2007
Registered User
 

Join Date: Nov 2007
Posts: 14
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
Reply With Quote
  #5  
Old 11-08-2007
Registered User
 

Join Date: Oct 2007
Posts: 155
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. One of those should work, though, and I'm pretty sure the syntax I wrote above is all wrong for tcsh.
Reply With Quote
  #6  
Old 11-08-2007
Registered User
 

Join Date: Nov 2007
Posts: 14
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.
Reply With Quote
  #7  
Old 11-08-2007
Registered User
 

Join Date: Nov 2007
Posts: 14
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
The only thing I can't figure out is how to drop the p and the space.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 07:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0