checking invoice number not correct


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking invoice number not correct
# 1  
Old 03-29-2007
checking invoice number not correct

hello,

I have the following script to check the invoice number is in order or not.
However, it cannot show out the correct information. My expect output show below and I would like to only list out the NOT IN SEQUENCE inovice number (not included "ok")

#!/bin/sh
start=1
for file_number in `ls -1 /appl/appl/archive/client/CACHE/CLIENTINVOICE*[0-9].archived | sort | cut -c 48,49,50,51`
do
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
# 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 "OK"
else
seqno=`expr $file_number - 1`
echo "CLIENTINVOICE$invoiceno are not in sequence "
fi
fi
previous=$file_number
done


input:
01185
01191
01192
01193
01196
01197
.
.
.

script output:
01190 are not in seq
01195 are not in seq

expect output
01186 are not in seq
01187 are not in seq
01188 are not in seq
01189 are not in seq
01190 are not in seq
01194 are not in seq
01195 are not in seq
# 2  
Old 03-29-2007
Code:
#! /opt/third-party/bin/perl

open(FILE, "<", a) || die "Unable to open file <$!>\n";

while(<FILE>) {
  chomp;
  if ( not defined $first ) {
    $first = $_;
    next;
  }
  for( $i = $first + 1; $i < $_; $i++ ) {
    print "0$i are not in seq\n";
  }
  $first = $_;
}

close(FILE);

exit 0

# 3  
Old 03-29-2007
Chk this:

Code:
awk '{ if (NR==1){ dat=$1; }else { while(++dat<$0) printf "%05d Are not in seq \n",  dat    }  }' filename

Output:

01186 Are not in seq
01187 Are not in seq
01188 Are not in seq
01189 Are not in seq
01190 Are not in seq
01194 Are not in seq
01195 Are not in seq
# 4  
Old 03-29-2007
Quote:
Originally Posted by jacoden
Chk this:

Code:
awk '{ if (NR==1){ dat=$1; }else { while(++dat<$0) printf "%05d Are not in seq \n",  dat    }  }' filename

Output:

01186 Are not in seq
01187 Are not in seq
01188 Are not in seq
01189 Are not in seq
01190 Are not in seq
01194 Are not in seq
01195 Are not in seq
Great, it work...but I problem..due to the directory have a lot of different group of invoice such as
CLIENTINVOICE*[0-9].archived
CLIENTBINVOICE*[0-9].archived
CLIENTCINVOICE*[0-9].archived


Can I output the result which the group name as well..? so that i can do summary for each group of missing.

expected:
CLIENTINVOICE01187 Are not in seq
CLIENTINVOICE01188 Are not in seq
CLIENTINVOICE01189 Are not in seq
CLIENTINVOICE01190 Are not in seq
CLIENTINVOICE01194 Are not in seq
CLIENTBINVOICE02201 Are not in seq
CLIENTBINVOICE02203 Are not in seq
CLIENTCINVOICE02203 Are not in seq
CLIENTCINVOICE02207 Are not in seq
CLIENTCINVOICE02212 Are not in seq
# 5  
Old 03-29-2007
Could you explain the problem with an example..
# 6  
Old 03-29-2007
Quote:
Originally Posted by jacoden
Could you explain the problem with an example..
I just want to have more output detail. your output:

Output:

01186 Are not in seq
01187 Are not in seq
01188 Are not in seq
01189 Are not in seq
01190 Are not in seq
01194 Are not in seq
01195 Are not in seq

my expected output (due to the file with a lot of client group in it)

group type:
CLIENTINVOICE*[0-9].archived
CLIENTBINVOICE*[0-9].archived
CLIENTCINVOICE*[0-9].archived

output:
CLIENTINVOICE01187 Are not in seq
CLIENTINVOICE01188 Are not in seq
CLIENTINVOICE01189 Are not in seq
CLIENTINVOICE01190 Are not in seq
CLIENTINVOICE01194 Are not in seq
CLIENTBINVOICE02201 Are not in seq
CLIENTBINVOICE02203 Are not in seq
CLIENTCINVOICE02203 Are not in seq
CLIENTCINVOICE02207 Are not in seq
CLIENTCINVOICE02212 Are not in seq
# 7  
Old 03-29-2007
Code:
input:
01185
01191
01192
01193
01196
01197

the input you gave is of the above form
is the input still the same ?
if so,

how is it possible to categorize as CLIENT, CLIENTB, CLIENTC ?
Is there any logic based on the numbers ? Smilie
To me its still not clear!

Again your sample input and expected output would be of great help!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Getting correct port number from process id

Hi All, i am trying to find the Jobss port number(either default port number or any other port number assigned) from the running process id. But it's giving me multiple port numbers when searching with netstat command. Can someone help me in finding the correct port number from the... (3 Replies)
Discussion started by: sravani25
3 Replies

2. Shell Programming and Scripting

Checking number of commas in each line.

Hi All, I am checking whether each line is having "n" number of commas or nor. In case not then I need to exit the process. I tried cat "$TEMP_FILE" | while read LINE do processing_line=`expr $processing_line + 1` no_of_delimiters=`echo "$LINE" | awk -F ',' '{ print NF }'` if ... (4 Replies)
Discussion started by: Anupam_Halder
4 Replies

3. Shell Programming and Scripting

checking a number

ok im trying to find out how many cars a user enters. Its giving me an error message of "integer expression expected" Basically if i enter any number over 0 (zero) it should continue read -p "How many cars:" carsn test $cars -ge 1 test $? -ne 0 && read -p "Invalid number.... (8 Replies)
Discussion started by: gangsta
8 Replies

4. Homework & Coursework Questions

checking for number of arguments.

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Your script must check for the correct number of arguments (one argument). If somebody tries to invoke the... (1 Reply)
Discussion started by: brooksie91
1 Replies

5. UNIX for Dummies Questions & Answers

Basic number checking problem

Hello all I am having problems using a bash script to read the input from the user and checking that its a valid number. I only want the user to input a maximum of a 3 number string (321 , 521 , 871 etc.). Anything longer or that includes a chararcter or symbol will display an error message. ... (8 Replies)
Discussion started by: ChrisHoogie
8 Replies

6. UNIX for Dummies Questions & Answers

checking if parameter passed is a number

I have written a function that fills an array and another function where if a parameter is supplied it will jump to that part of the array and cat it to the screen. I need to put in some checks to make sure the parameter supplied is firstly a number and then not a number great than the length of... (2 Replies)
Discussion started by: magnia
2 Replies

7. Programming

Problem in getting the correct number from the string.

I have string named texts which consist of section label “BOOK-SEC-“. Section starts from 1 to n, where n is a number. For this example conside the value of n is 9. That is, the string variable looks like “BOOK-SEC-1... (2 Replies)
Discussion started by: SamRoj
2 Replies

8. Shell Programming and Scripting

Checking for proper number of files in dir

Using Solaris 10 and sh. I have three files. mydirs.txt /dir1/dir2/dir3 /dir4/dir5/dir6 mydirshave.txt 1 2 mydirsshouldhave.txt 2 2 For each directory listed in mydirs.txt I should have the number of files equal to mydirshouldhave.txt. But using -ls |wc -l- on the dirs I get what... (2 Replies)
Discussion started by: crowman
2 Replies

9. Shell Programming and Scripting

checking the smallest and largest number

Hi All, My script is reading a log file line by line log file is like ; 19:40:22 :INFO Total time taken to Service External Request---115ms 19:40:25 DEBUG : Batch processed libdaemon.x86_64 0-0.10-5.el5 - u 19:40:22 INFO Total time taken to Service External Request---20ms 19:40:24... (4 Replies)
Discussion started by: subin_bala
4 Replies

10. UNIX for Dummies Questions & Answers

sequence number checking

Hi there, I'm wanting to produce a shell script that will check through some file names and identify a skip in sequence (four digit seq num in file name). I have played on the idea of havng a file that has a sorted list of file names which I can read line at a time and cut out the sequence... (1 Reply)
Discussion started by: nhatch
1 Replies
Login or Register to Ask a Question