![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| merging of files ! not in sequential in paralel | arunkumar_mca | UNIX for Dummies Questions & Answers | 1 | 02-14-2008 08:28 AM |
| Reading special characters while converting sequential file to line sequential | Rajeshsu | High Level Programming | 2 | 07-10-2006 11:38 AM |
| listing members of a unix group | ovaska | UNIX for Dummies Questions & Answers | 2 | 03-09-2005 01:54 PM |
| Recursive directory listing without listing files | psingh | UNIX for Dummies Questions & Answers | 4 | 05-10-2002 07:52 AM |
| indexed sequential access in c files | vrkiruba | High Level Programming | 0 | 05-23-2001 12:42 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
listing sequential files as one group...
Hi,
I posted this over at Macnn and was redirected here... I'm not a unix programmer at all, but I have some backup if needed. Thanks in advance for any input. Is there a command for the osX terminal that will list sequentially numbered groups of file as one line instead of individually, while listing other files and directories correctly? Meaning that a group of files: image.001.tif image.002.tif image.003.tif image.004.tif image.005.tif would be listed as image.001-005.tif and a dir with other files and dirs: image.001.tif image.002.tif image.003.tif image.004.tif image.005.tif dir01/ dir02/ imageB.tif in it would be: image.001-005.tif dir01/ dir02/ imageB.tif ? Wold love to have this... Thanks, KM |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|||
| Google UNIX.COM |