The UNIX and Linux Forums  

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 here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to ensure lines are in sequence docaia Shell Programming and Scripting 5 05-30-2008 01:13 PM
checking jump sequence number (part2) happyv Shell Programming and Scripting 3 10-19-2006 03:03 AM
Script in boot sequence delphine UNIX for Dummies Questions & Answers 1 01-25-2006 08:20 AM
Script to check for a file, check for 2hrs. then quit mmarsh UNIX for Dummies Questions & Answers 2 09-16-2005 11:46 AM
Knoppix ---> Slackware the big jump, should I? Jace UNIX for Dummies Questions & Answers 7 12-16-2004 09:53 AM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-19-2006
Registered User
 

Join Date: Sep 2006
Posts: 209
help - script can check jump sequence?

Hi,

if I have a lot of files like (AABBCC0010, AABBCC0011, AABBCC0012....AABBCC1000), can I write a small script to check any sequence number jump and show me the result which sequence number?

#The first sequence may start from 0010 or 0101...

Thank you!!
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-20-2006
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 767
You can write a small script to do that. Here is one that I wrote:

#!/bin/sh
start=1

for file_number in `ls -1 AABBCC* | sort | cut -c 7,8,9,10`
do
if [ $start = 1 ] ; then
# this is the first pass of the loop, so we've got nothing to compare
start=0
else
# this is not the first pass of the loop
previous=`expr $previous + 1`
echo "comparing $file_number and $previous ... "
if [ $file_number = $previous ] ; then
echo "file names are in sequence "
else
echo "file names $file_number are not in sequence "
fi
fi
previous=$file_number
done

I assumed that filenames are AABBCCxxxx where xxxx is a number, which is of interest to us. Please note that this script does not work with smaller numbers, of 3 digits and 2 digits. Reason is that expr strips the leading zeros in such numbers (0010 becomes 10 which then breaks the sequence)
Reply With Quote
  #3 (permalink)  
Old 09-20-2006
Registered User
 

Join Date: Sep 2006
Posts: 209
not work..
when I run the script, it showing the error below:

expr: non-numeric argument
comparing SIMAC and ...
ksh: test: argument expected
file names SIMAC are not in sequence
expr: non-numeric argument
comparing SIMAC and ...
ksh: test: argument expected
file names SIMAC are not in sequence
expr: non-numeric argument
Reply With Quote
  #4 (permalink)  
Old 09-20-2006
Dhruva's Avatar
Registered User
 

Join Date: Mar 2006
Location: India
Posts: 255
if [ $start = 1 ] replace with if [ $start -eq 1 ]
and if [ $file_number = $previous ] with if [ $file_number -eq $previous ]
Reply With Quote
  #5 (permalink)  
Old 09-20-2006
Yogesh Sawant's Avatar
Part Time Moderator and Full Time Dad
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 767
You are using ksh to execute this script. Try using sh. Run it as:

$ sh scriptname

where scriptname is the name of the script
Reply With Quote
  #6 (permalink)  
Old 09-20-2006
Registered User
 

Join Date: Sep 2006
Posts: 209
I try to run:

sh checkseq (scriptname)

it showing:

expr: non-numeric argument
comparing SIMAC and ...
checkseq: test: argument expected
Reply With Quote
  #7 (permalink)  
Old 09-20-2006
aigles's Avatar
Registered User
 

Join Date: Apr 2004
Location: Bordeaux, France
Posts: 1,211
The variable previous is not initialised.
Modify the script :
Code:
if [ $start -eq 1 ] ; then
   # this is the first pass of the loop, so we've got nothing to compare
   start=0
   previous=$file_number
else

Jean-Pierre.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 03:02 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0