LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 01-07-2006, 10:32 PM   #1
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Rep: Reputation: 31
Finding gaps with 'ls' or some other command


I'm trying to figure out how to find the gaps in a list of file in one of my directories. I have a list of file from 001.txt to 799.txt and I'm trying to figure out how to find any gap in numbers besides counting them one by one.

Anyone know of a way I can do this?

Last edited by mijohnst; 01-07-2006 at 10:35 PM.
 
Old 01-08-2006, 01:39 AM   #2
T.Hsu
Member
 
Registered: Jan 2005
Posts: 178

Rep: Reputation: 31
for i in `seq -w 001 799`
do
if test ! -f $i.txt; then
echo "$i.txt is missing"
fi
done

Last edited by T.Hsu; 01-08-2006 at 01:41 AM.
 
Old 01-08-2006, 02:26 AM   #3
Cirdan
Member
 
Registered: Nov 2005
Distribution: Arch Linux
Posts: 84

Rep: Reputation: 15
Quote:
Originally Posted by T.Hsu
for i in `seq -w 001 799`
do
if test ! -f $i.txt; then
echo "$i.txt is missing"
fi
done
Don't you just love shell scripting Thanks for the code, I was wondering how you wouldaccomplish this also.
 
Old 01-08-2006, 07:32 AM   #4
T.Hsu
Member
 
Registered: Jan 2005
Posts: 178

Rep: Reputation: 31
Sorry for my poor English comprehension , "gap in numbers" means numerical range like "005 - 010"? then;

Code:
#!/bin/bash
num1=1
num2=$[num1+1]

while [[ num1 -lt 799 ]] ; do
	if [ ! -f `printf "%003d" $num1`.txt ]; then
		until [ -f `printf "%003d" $num2`.txt ]; do
		num2=$[num2+1]
		done
		if [ $num1 != $[num2-1] ]; then
		echo `printf "%003d" $num1`.txt to `printf "%003d" $[num2-1]`.txt are missing.
		else
		echo `printf "%003d" $num1`.txt is missing.
		fi
		num1=$num2
	fi
	num1=$[num1+1]
	num2=$[num1+1]
done

Last edited by T.Hsu; 01-08-2006 at 08:20 PM.
 
Old 01-08-2006, 09:49 PM   #5
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Original Poster
Rep: Reputation: 31
You all are awesome... Thank you so much!
 
Old 01-09-2006, 04:59 PM   #6
mijohnst
Member
 
Registered: Nov 2003
Location: Huntsville, AL
Distribution: RHEL, Solaris, OSX, SuSE
Posts: 419

Original Poster
Rep: Reputation: 31
I was looking for a way to do the same to directories... I changed the -f to -d and worked great! Thanks so much!

Last edited by mijohnst; 01-09-2006 at 05:33 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to paginate in the 'LS' command? jhecht Linux - Software 10 04-13-2010 06:15 AM
Dependecy gaps between udev 0.074 and linux-image 2.6.12 TheOneKEA Debian 3 11-18-2005 05:40 PM
alias cs='cd $1; ls' milanche Linux - Newbie 11 09-13-2005 05:57 PM
CD audio gaps problem cscott Linux - Software 1 08-27-2004 09:15 PM
'ls' command... sramelyk Slackware 7 10-01-2003 12:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration