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
Processing a log file based on date/time input and the date/time on the log file primp Shell Programming and Scripting 4 03-16-2008 11:23 AM
read a list one at a time nortypig Shell Programming and Scripting 7 08-27-2006 09:50 PM
why shell scripting takes more time to read a file brkavi_in Shell Programming and Scripting 1 06-23-2006 08:20 AM
Terminal Hungup at the time of read pkusumam Shell Programming and Scripting 1 11-30-2001 04:19 AM
How to read and write files one line at a time. s_chopra UNIX for Dummies Questions & Answers 2 04-18-2001 09:39 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 06-22-2007
cedrichiu cedrichiu is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
How to read max of 10 file at a time?

Hi All,

Please advise . Welcome more suggestions.

For examples, I have 1000 file with prefix x??? In fact, I want to convert them to x???.txt with max 10 files at a time. As such, I will need to call another script to read from those 10 *txt files and sleep 5000 to convert the next 10 again.

xaaa
;
;
xbbz

Hope to hear from.

Regards,
  #2 (permalink)  
Old 06-22-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
You can do something like that:

Code:
count=0
limit=10
ls x??? | \
while read file
do
   mv $file $file.txt
   count=`expr $count+1`
   if [ $count -ge $limit ]
   then
      count=0
      /path/to/another_script &
      sleep 5000  # Wait more than an hour (5000 secs)
   fi
done
  #3 (permalink)  
Old 06-22-2007
Shell_Life's Avatar
Shell_Life Shell_Life is offline
Registered User
  
 

Join Date: Mar 2007
Location: Bahia, Brazil
Posts: 695
Aigles, about your solution:
1) It does not work if the number of files is not multiple of 10.
2) The user is asking to work with 10 files at a time.
You are working with one at a time.

Here is one possible solution to rename the files:
Code:
for mFile in x???
do
  mv $mFile $mFile".txt"
done
Here is the solution to work with groups of 10 files at a time:
Code:
set -- x???.txt
printf "%s %s %s %s %s %s %s %s %s %s\n" $@ | \
while read m10Files
do
  echo "m10Files = "${m10Files}
done
  #4 (permalink)  
Old 06-22-2007
aigles's Avatar
aigles aigles is offline Forum Advisor  
Registered User
  
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,416
Quote:
Originally Posted by Shell_Life View Post
Aigles, about your solution:
1) It does not work if the number of files is not multiple of 10.
2) The user is asking to work with 10 files at a time.
You are working with one at a time.
1) Exact. The following new version fix it.
2) The script is called every ten files. I add a variable containing the file names (can be used as a parameter for the script)

Code:
count=0
file_list=
limit=10
ls x??? | \
while read file
do
   mv $file $file.txt
   count=`expr $count+1`
   file_list="$file_list $file.txt"
   if [ $count -ge $limit ]
   then
      /path/to/another_script $file_list &
      sleep 5000  # Wait more than an hour (5000 secs)
      count=0
      file_list=
   fi
done
[ $count -gt 0 ] && /path/to/another_script $file_list &
I"m not sure that running the script in background is required. If not remove the &
  #5 (permalink)  
Old 06-22-2007
cedrichiu cedrichiu is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
Hi aigles and Shell_Life,

Thanks for yours input. I will give a try.
Cheers
  #6 (permalink)  
Old 06-23-2007
cedrichiu cedrichiu is offline
Registered User
  
 

Join Date: Mar 2007
Posts: 17
Code:
count=0
limit=10
mydate=`date '+%Y%m%d%H%M%S'`

cd /var/tmp/VAS

for mFile in x????
do
     mv $mFile $mFile".txt"
     count=`expr $count+1`
     if [ $count -le $limit ]
     then
          sh up.sh 2>LOG/update.sh.$mydate.log &
          sleep 5000
          mv *out LOG/
          count=0
  fi
done
The counter doesn't increase at at and file are mv at all and. It won't stop at limit 10th...

Something wrong... Please advise
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 06:58 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