The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 09:18 AM
Looping/Repetition in Batch files kimpot7268 Shell Programming and Scripting 2 12-12-2005 08:45 AM
Looping/Repetition in Batch files kimpot7268 UNIX for Advanced & Expert Users 1 12-10-2005 04:49 AM
Help looping through files, please... kapolani Shell Programming and Scripting 2 10-27-2004 01:28 PM
looping files dharmesht Shell Programming and Scripting 5 12-03-2003 06:36 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-07-2007
Fred Goldman Fred Goldman is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 25
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 05:59 PM..
  #2 (permalink)  
Old 11-07-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
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.
  #3 (permalink)  
Old 11-07-2007
Fred Goldman Fred Goldman is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 25
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 (permalink)  
Old 11-08-2007
Fred Goldman Fred Goldman is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 25
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 (permalink)  
Old 11-08-2007
gus2000 gus2000 is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 157
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.
  #6 (permalink)  
Old 11-08-2007
Fred Goldman Fred Goldman is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 25
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.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:32 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0