Sponsored Content
Operating Systems OS X (Apple) Check file sequence script not working. Need help. Post 302516866 by Corona688 on Monday 25th of April 2011 12:42:14 PM
Old 04-25-2011
You agreed not to bump posts when you registered.

You're certainly not running it in bash, not sure why you mention it at all.

I see nothing in that code which would have ever added leading zeroes to your strings.

There's plenty of things in your script which in a bourne shell would be "useless use of ls *" and the like but in csh these constructs may actually be necessary...

But whether your shell be csh or zsh or whatever you can't exit -1, that value's nonsensical. It has to be a positive value between 0-255 inclusive.

Most of us aren't too fluent in CSH for a variety of reasons which cts already linked. You'd do better to learn a real scripting language. Trying a solution in bash for you.

I surmise that the version of csh you used to use had these :r etc string operations. Mine certainly doesn't and may be what broke down when you brought this script over.

---------- Post updated at 10:42 AM ---------- Previous update was at 09:49 AM ----------

Code:
#!/bin/bash

MAX=0   MIN=999999      TOTAL=0

# Don't have functions in csh.  Can't redirect to stderr properly either.
function die    # Print an error message to stderr, return 1
{
        echo "$@" >&2   ;       exit 1
}

[ "$#" -ne 1 ] && die "Usage: $0 <prefix>"      # Die unless exactly 1 arg

# Loop over all files.  (NOTE: May exceed argmax in other shells)
for I in ${1}.[0-9][0-9][0-9][0-9][0-9].dpx
do
        [ -f "$I" ] || die "No files found for prefix $1"
        # csh doesn't have a proper 'read'.  You can read from your TTY, that's it
        IFS="." read G C G <<< "$I"     # Extract number from string

        # Strip all leading zeroes
        while [ "${C:0:1}" == "0" ] && [ ! -z "${C:1:1}" ]
        do
                C="${C##0}"
        done

        [ "$C" -gt "$MAX" ] && MAX=$C   # Update max
        [ "$C" -lt "$MIN" ] && MIN=$C   # Update min
        ((TOTAL++))
done

for ((N=MIN; N<=MAX; N++))
do
        FILE=$(printf "%s.%05d.%s" "$1" $N "dpx")

        [ -f "$FILE" ] || echo "$FILE missing" >&2
done

[ "$TOTAL" -lt "$(((MAX-MIN)+1))" ] &&
        die "$((((MAX-MIN-TOTAL)+1))) files missing"

printf "No files missing in %s.%05d.dpx - %s.%05d.dpx\n" $1 $MIN $1 $MAX >&2

exit 0


Last edited by Corona688; 04-25-2011 at 05:28 PM.. Reason: Moved TOTAL++ to simplify code
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Script to check for a file, check for 2hrs. then quit

I wish to seach a Dir for a specific file, once the file is found i will perform additional logic. If the file is not found within two hours, i would like to exit. Logically, I'm looking for the best way to approach this Thanks for any assistance in advance. Note: I'm using a C shell and... (2 Replies)
Discussion started by: mmarsh
2 Replies

2. Shell Programming and Scripting

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... :confused: Thank you!! (10 Replies)
Discussion started by: happyv
10 Replies

3. Shell Programming and Scripting

Script to check file sequence

Hi everyone, I need help in creating a script that would check if the file sequence is in order in a particular directory. These are log files that are generated throughout the day. Example of the file name will be, ABC01_YYMMDDHHMM###### (ABC01_0904161829000001) Sometimes the file... (4 Replies)
Discussion started by: kumaran21
4 Replies

4. Shell Programming and Scripting

Script to check for the file existence, if file exists it should echo the no of modified days

Hi, I am looking for a shell script with the following. 1. It should check whether a particular file exists in a location #!/bin/sh if ; then echo "xxx.txt File Exists" else echo "File Not Found" fi 2. If file exists, it should check for the modified date and run a command... (2 Replies)
Discussion started by: karthikeyan_mac
2 Replies

5. Shell Programming and Scripting

Check Sequence

* Expiry DATE: * Address1: Address2: Address3: Address4: Address5: * PO_ref_number: aadad HolderId_1: HolderId_2: HolderId_3: HolderId_4: * adad: 00000 ada: 00000 adad: RANDOM adad: RANDOM ****************************** (4 Replies)
Discussion started by: arunshankar.c
4 Replies

6. Shell Programming and Scripting

find common entries and match the number with long sequence and cut that sequence in output

Hi all, I have a file like this ID 3BP5L_HUMAN Reviewed; 393 AA. AC Q7L8J4; Q96FI5; Q9BQH8; Q9C0E3; DT 05-FEB-2008, integrated into UniProtKB/Swiss-Prot. DT 05-JUL-2004, sequence version 1. DT 05-SEP-2012, entry version 71. FT COILED 59 140 ... (1 Reply)
Discussion started by: manigrover
1 Replies

7. Shell Programming and Scripting

How to check missing sequence?

I want to listed files every hours and check the missing sequence my file format is CV.020220131430.txt CV.020220131440.txt CV.020220131450.txt CV.ddmmyyhhm.txt how to check if i have missing files in sequence .. thanks (3 Replies)
Discussion started by: before4
3 Replies

8. Solaris

Escape Sequence for Capital Letters Input at Shell Not Working

Hello, I am running Solaris 8. When issuing the command "stty lcase" all text which is output to the terminal are capitalized. Letters that are supposed to be capitals are preceded by a backslash during output. All text which is input is converted to lower case. This is the expected behaviour... (5 Replies)
Discussion started by: rstor
5 Replies

9. Shell Programming and Scripting

Shell script check syntax not working ...

Hello i have question that i want check syntax from my script shell with sh -n filename but it's not show something even i have wrong syntax in my file. why can this happened or any other way to check it? i use on header of file : #!/bin/sh thx before :) (7 Replies)
Discussion started by: Gochengz
7 Replies

10. Shell Programming and Scripting

To check the missing file based on sequence number.

Hi All, I have a requirement that i need to list only the missing sequences with a unix script. For Example: Input: FILE_001.txt FILE_002.txt FILE_005.txt FILE_006.txt FILE_008.txt FILE_009.txt FILE_010.txt FILE_014.txt Output: FILE_003.txt FILE_004.txt FILE_007.txt FILE_011.txt... (5 Replies)
Discussion started by: Arun1992
5 Replies
getusershell(3C)					   Standard C Library Functions 					  getusershell(3C)

NAME
getusershell, setusershell, endusershell - get legal user shells SYNOPSIS
#include <unistd.h> char *getusershell(void); void setusershell(void); void endusershell(void); DESCRIPTION
The getusershell() function returns a pointer to a legal user shell as defined by the system manager in the file /etc/shells. If /etc/shells does not exist, the following locations of the standard system shells are used in its place: /bin/bash /bin/csh /bin/jsh /bin/ksh /bin/ksh93 /bin/pfcsh /bin/pfksh /bin/pfsh /bin/sh /bin/tcsh /bin/zsh /sbin/jsh /sbin/pfsh /sbin/sh /usr/bin/bash /usr/bin/csh /usr/bin/jsh /usr/bin/ksh /usr/bin/ksh93 /usr/bin/pfcsh /usr/bin/pfksh /usr/bin/pfsh /usr/bin/sh /usr/bin/tcsh /usr/bin/zsh /usr/sfw/bin/zsh /usr/xpg4/bin/sh The getusershell() function opens the file /etc/shells, if it exists, and returns the next entry in the list of shells. The setusershell() function rewinds the file or the list. The endusershell() function closes the file, frees any memory used by getusershell() and setusershell(), and rewinds the file /etc/shells. RETURN VALUES
The getusershell() function returns a null pointer on EOF. BUGS
All information is contained in memory that may be freed with a call to endusershell(), so it must be copied if it is to be saved. NOTES
Restricted shells should not be listed in /etc/shells. SunOS 5.11 1 Nov 2007 getusershell(3C)
All times are GMT -4. The time now is 10:18 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy