Sponsored Content
Top Forums UNIX for Advanced & Expert Users listing sequential files as one group... Post 302104311 by sb008 on Wednesday 24th of January 2007 05:11:36 PM
Old 01-24-2007
Surely this can be done better, but it was a quick job

----------------------------------------------------------------
script
----------------------------------------------------------------

#!/usr/bin/ksh

for DIR in `find tmp -type d`
do
EXPECT=""
FIRST=""
LAST=""

for FILE in `find ${DIR}/* -prune -type f 2> /dev/null`
do
if [ "${FILE}" != "${EXPECT}" ]
then
if [ "${LAST}" != "" ]
then
if [ "${FIRST}" == "${LAST}" ]
then
echo "${FIRST}"
else
typeset -i LEN
((LEN=`echo ${LAST} | sed -e "s/.*[^0-9]\([0-9][0-9]*\)[^0-9]*$/\1/" | wc -c`-1))
typeset -Z${LEN} NUM NEXTNUM
NUM=`echo ${LAST} | sed -e "s/.*[^0-9]\([0-9][0-9]*\)[^0-9]*$/\1/"`
echo "${FIRST}" | sed -e "s/\([^0-9][^0-9]*\)$/-${NUM}\1/"
fi
fi
FIRST=${FILE}
fi

LAST=${FILE}

echo ${LAST} | grep [0-9] > /dev/null
if [ ${?} -eq 0 ]
then
typeset -i LEN
((LEN=`echo ${LAST} | sed -e "s/.*[^0-9]\([0-9][0-9]*\)[^0-9]*$/\1/" | wc -c`-1))
typeset -Z${LEN} NUM NEXTNUM
NUM=`echo ${LAST} | sed -e "s/.*[^0-9]\([0-9][0-9]*\)[^0-9]*$/\1/"`
((NEXTNUM=${NUM}+1))
EXPECT=`echo ${LAST} | sed -e "s/${NUM}/${NEXTNUM}/"`
fi
done

if [ "${LAST}" != "" ]
then
if [ "${FIRST}" == "${LAST}" ]
then
echo "${FIRST}"
else
typeset -i LEN
((LEN=`echo ${LAST} | sed -e "s/.*[^0-9]\([0-9][0-9]*\)[^0-9]*$/\1/" | wc -c`-1))
typeset -Z${LEN} NUM NEXTNUM
NUM=`echo ${LAST} | sed -e "s/.*[^0-9]\([0-9][0-9]*\)[^0-9]*$/\1/"`
echo "${FIRST}" | sed -e "s/\([^0-9][^0-9]*\)$/-${NUM}\1/"
fi
fi
done

----------------------------------------------------------------
The tree below some directory tmp
----------------------------------------------------------------

tmp:
total 1
-rw-r--r-- 1 user group 0 Jan 24 22:46 afile
drwxr-xr-x 2 user group 256 Jan 24 23:01 dir01
drwxr-xr-x 2 user group 432 Jan 24 23:05 dir02
-rw-r--r-- 1 user group 0 Jan 24 21:29 image.001.tif
-rw-r--r-- 1 user group 0 Jan 24 21:29 image.002.tif
-rw-r--r-- 1 user group 0 Jan 24 21:29 image.003.tif
-rw-r--r-- 1 user group 0 Jan 24 21:29 image.004.tif
-rw-r--r-- 1 user group 0 Jan 24 21:30 image.005.tif
-rw-r--r-- 1 user group 0 Jan 24 22:46 image.008.tif
-rw-r--r-- 1 user group 0 Jan 24 22:46 image.009.tif
-rw-r--r-- 1 user group 0 Jan 24 21:30 imageB.tif
-rw-r--r-- 1 user group 0 Jan 24 22:46 maybeafile
-rw-r--r-- 1 user group 0 Jan 24 22:46 nofile

tmp/dir01:
total 0
-rw-r--r-- 1 user group 0 Jan 24 22:53 anotherfile
-rw-r--r-- 1 user group 0 Jan 24 22:53 bigfile
-rw-r--r-- 1 user group 0 Jan 24 22:53 emptyfile
-rw-r--r-- 1 user group 0 Jan 24 22:53 file03.aap
-rw-r--r-- 1 user group 0 Jan 24 22:53 file04.aap
-rw-r--r-- 1 user group 0 Jan 24 22:53 file05.aap
-rw-r--r-- 1 user group 0 Jan 24 23:01 x-file

tmp/dir02:
total 0
-rw-r--r-- 1 user group 0 Jan 24 23:05 anothersingle18.jpg
-rw-r--r-- 1 user group 0 Jan 24 23:05 closedfile
-rw-r--r-- 1 user group 0 Jan 24 23:05 movie11.div
-rw-r--r-- 1 user group 0 Jan 24 23:05 movie12.div
-rw-r--r-- 1 user group 0 Jan 24 23:05 openfile
-rw-r--r-- 1 user group 0 Jan 24 23:05 pic107.jpg
-rw-r--r-- 1 user group 0 Jan 24 23:05 pic108.jpg
-rw-r--r-- 1 user group 0 Jan 24 23:05 pic109.jpg
-rw-r--r-- 1 user group 0 Jan 24 23:05 pic110.jpg
-rw-r--r-- 1 user group 0 Jan 24 23:05 pic111.jpg
-rw-r--r-- 1 user group 0 Jan 24 23:05 singlepoc07.bmp
-rw-r--r-- 1 user group 0 Jan 24 23:05 smallfile

----------------------------------------------------------------
The output
----------------------------------------------------------------

tmp/afile
tmp/image.001-005.tif
tmp/image.008-009.tif
tmp/imageB.tif
tmp/maybeafile
tmp/nofile
tmp/dir01/anotherfile
tmp/dir01/bigfile
tmp/dir01/emptyfile
tmp/dir01/file03-05.aap
tmp/dir01/x-file
tmp/dir02/anothersingle18.jpg
tmp/dir02/closedfile
tmp/dir02/movie11-12.div
tmp/dir02/openfile
tmp/dir02/pic107-111.jpg
tmp/dir02/singlepoc07.bmp
tmp/dir02/smallfile
 

10 More Discussions You Might Find Interesting

1. Programming

indexed sequential access in c files

hi, I want to implement indexed sequential access method in my flat file, Any idea other than INFORMIX C-ISAM library, because it is not free ware, Any Freeware available? (0 Replies)
Discussion started by: vrkiruba
0 Replies

2. UNIX for Dummies Questions & Answers

Recursive directory listing without listing files

Does any one know how to get a recursive directory listing in long format (showing owner, group, permission etc) without listing the files contained in the directories. The following command also shows the files but I only want to see the directories. ls -lrtR * (4 Replies)
Discussion started by: psingh
4 Replies

3. UNIX for Dummies Questions & Answers

listing members of a unix group

I know there is a "groups" command to list the groups a user belongs to, but how about the opposite? Is there a standard command to find out which users belong to a particular group? (2 Replies)
Discussion started by: ovaska
2 Replies

4. Programming

Reading special characters while converting sequential file to line sequential

We have to convert a sequential file to a 80 char line sequential file (HP UX platform).The sequential file contains special characters. which after conversion of the file to line sequential are getting coverted into "new line" or "tab" and file is getting distorted. Is there any way to read these... (2 Replies)
Discussion started by: Rajeshsu
2 Replies

5. UNIX for Dummies Questions & Answers

merging of files ! not in sequential in paralel

Hi , I am having 3 files as FILE1 1 2 3 FILE2 4 5 6 FILE3 7 8 9 I want to merge thes file such that the resultnt file should be as (1 Reply)
Discussion started by: arunkumar_mca
1 Replies

6. UNIX for Advanced & Expert Users

script regarding listing long group names

Hello, When listing the file systems (using ls -ltr) , if the group names are longer the group name is getting truncated. Can someone help with the script which would display the truncated group name? I appreciate if someone could help in this regard. (1 Reply)
Discussion started by: mike12
1 Replies

7. Programming

Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX

Writing a Tool to simulate non-sequential disk I/O (simulate db file sequential read) in C POSIX I have over the years come across the same issue a couple of times, and it normally is that the read speed on SAN is absolutely atrocious when doing non-sequential I/O to the disks. Problem being of... (7 Replies)
Discussion started by: vrghost
7 Replies

8. Shell Programming and Scripting

Rename files in sub directories with sequential numbers

I can rename a file with sequential numbers from 1 to N with this script: num=1 for file in *.dat;do mv "$file" "$(printf "%u" $num).txt" let num=num+1 done The script begins with renaming a some.dat file to 1.dat.txt and goes on sequentially renaming other DAT files to... (1 Reply)
Discussion started by: shoaibjameel123
1 Replies

9. Shell Programming and Scripting

Execute sequential files and store data in single file

1)In a particualr path i have a set of inputfiles like path:/defaultmis/MonthlyLoads/INFA_EXPORT_022013/map* example: 1)map_de 2)map_cod 3)map_feg ........and so on in above path there wil be nearly 15 to 20 files starting with map and in other path i have another file input file... (4 Replies)
Discussion started by: katakamvivek
4 Replies

10. Shell Programming and Scripting

Run sequential test files

I have c program that I run like this: ./a.out t1 And my test files look like this all the way up to 100: t1 t2 t3 Is there a way to run this more efficiently so I don't have to hit up and change the number every time? (4 Replies)
Discussion started by: cokedude
4 Replies
All times are GMT -4. The time now is 04:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy