Sponsored Content
Full Discussion: For loop sequence issue
Top Forums Shell Programming and Scripting For loop sequence issue Post 302438469 by rss0213 on Monday 19th of July 2010 10:59:06 PM
Old 07-19-2010
Yes, rdc.... you're on the right track. This was the actual solution that I went with:

Code:
   cd $IMGPATH
   for file in $(ls | sort -n); do
      count=$((count + 1))
      count_str=$(printf "%04d" $count)
      mv $file $LBOX$DATEDIR$count_str"0.tif"
   done

The problem was that the transactions in the csv file had the tif images listed as 1.tif, 2.tif, 3.tif, ..., n.tif, but the previous code was sorting them as 1.tif, 10.tif, 100.tif, etc. So the 2nd transaction in the output csv referenced the 10th tif image, the 3rd referenced the 100th tif image, and so on.

It has to do with the way unix sorts (collates) values in a "for i in *.tif..." looping scenario. If one needs to have the numeric portion of the file names to maintain their sequence value, then my code above works.

Thanks for everyone's help.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help With A For Loop Issue

I was wondering how I can modify this for loop, so it only loops through the filenames that do not have an ".old" extension. for filename in $(ls "$1") do echo $filename | grep '\.old$' > /dev/null if then mv $1/$filename $1/$filename.old fi done (5 Replies)
Discussion started by: ralts01
5 Replies

2. Shell Programming and Scripting

while loop issue

Hi, Following is my code and the file FILE_LIST_EXCESS.txt has 40 file names in it while read LineIn do echo ${LineIn} `ftp -vin << END_INPUT >> ${PID}_DS_GET_Log.log 2>&1 open servername user userid password cd FileDir get ${LineIn} END_INPUT`... (4 Replies)
Discussion started by: mgirinath
4 Replies

3. Shell Programming and Scripting

For Loop sequence question

I am using a for loop in a shell. My question is how does it list out the files in the example below. Does it list the files by name? How can I list the files by date so it will list the oldest file first in the sequence. Thanks! for f in /dir/*.* echo $f end (2 Replies)
Discussion started by: stringzz
2 Replies

4. Shell Programming and Scripting

loop issue

function ext { echo "THANKS & WELCOME BACK" } function upc { echo "TO EXPORT UPROC GIVE UPROC NAME PER LINE IN THE input.txt and PRESS Y" echo "TO GO BACK PRESS 99" read parm0 if ; then start elif ; then for i in `cat input.txt` ; do echo $i $UXEXE/uxext upr upr=$i... (0 Replies)
Discussion started by: kojo
0 Replies

5. Shell Programming and Scripting

until loop issue.

Hi, my script is waiting for 3 files to come to a folder for 30 min but even when all the files arrive in the folder it's still waiting for these three files. Files can come with in 2 min and I want it to start processing them immediately after all the files arrive in the folder. until ; do... (3 Replies)
Discussion started by: gurpartap
3 Replies

6. Shell Programming and Scripting

Issue with using While loop

Hi, I am trying to move a file from remote server to local server and when the transfer completes successfully i call a script in remote server to remove the file which was successfully transferred. I do this by first getting the list of file in remote server and move the text file to local... (8 Replies)
Discussion started by: funonnet
8 Replies

7. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

8. Shell Programming and Scripting

While Loop issue

Hi, i=0 t5=6000001 while do i=`expr $i + 1` t5=`expr $t5 + 1` echo $t5 done I am able to increment "col3" value but unable to get col1,col2 value. Input: t1=10001 t2=abc t3=ghkc (5 Replies)
Discussion started by: onesuri
5 Replies

9. Shell Programming and Scripting

Issue with for loop

Hi Team, I have for loop in my shell script. Which basically loop through all files in the directory, When some files are in the directory it works just fine. But if there are no files at all..still the for loop try to execute. Please help. Below is the code. #!/bin/ksh echo "Program... (5 Replies)
Discussion started by: bharath561989
5 Replies

10. UNIX for Beginners Questions & Answers

Issue when doing a loop

Hi, I just have started learning shell scripting (sh). Why do i only get the date? while read dt do echo "Date : ${dt} sed -n '/${dt}/,/${dt}/p' file1.log | grep -w ERROR done < date1.dat INPUT - date1.dat 2019-04-05 04:58:25 2019-04-05 04:58:26 2019-04-05 05:00:56... (3 Replies)
Discussion started by: margel
3 Replies
rgb2ycbcr(1)							   User Commands						      rgb2ycbcr(1)

NAME
rgb2ycbcr - convert non-YCbCr TIFF images to YCbCr TIFF images SYNOPSIS
rgb2ycbcr [options] src1.tif [src2.tif...] dest.tif DESCRIPTION
rgb2ycbcr converts RGB color, grayscale, or bi-level TIFF images to YCbCr images by transforming and sampling pixel data. If multiple files are specified on the command line, each source file is converted to a separate directory in the destination file. By default, chrominance samples are created by sampling 2 by 2 blocks of luminance values, and output data files are compressed with the LZW compression scheme, with each strip no more than 8 kilobytes. These characteristics can be overridden or explicitly specified with the options described below. OPTIONS
The following options are supported: -c Specify a compression scheme to use when writing image data: -c jpeg Baseline JPEG compression algorithm. -c lzw Lempel-Ziv and Welch algorithm. This is the default algorithm. -c none No compression. -c packbits PackBits compression algorithm. -h Set the horizontal sampling dimension to one of the following: 1, 2, or 4. The default value is 2. -r Write data with a specified number of rows per strip. By default, the number of rows per strip is selected so that each strip is approximately 8 kilobytes. -v Set the vertical sampling dimension to one of the following: 1, 2, or 4. The default value is 2. OPERANDS
The following operands are supported: src.tif The name of the input file that contains non-YCbCr TIFF data. dest.tif The name of the output file that contains YCbCr TIFF data. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWTiff | +-----------------------------+-----------------------------+ |Interface stability |External | +-----------------------------+-----------------------------+ SEE ALSO
tiffinfo(1), tiffcp(1), libtiff(3) NOTES
Updated by Breda McColgan, Sun Microsystems Inc., 2004. SunOS 5.10 26 Mar 2004 rgb2ycbcr(1)
All times are GMT -4. The time now is 09:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy