How to takes the missing files in ascending order


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users How to takes the missing files in ascending order
# 1  
Old 09-07-2012
How to takes the missing files in ascending order

Hi am using unix aix
we have a lots of files which comes from server and fetch in one directory. the files will be in the format as

File name as :
-------------

Code:
pprr0103 (01 as date and 03 as month)
pprr0203
pprr0603
...
...
pprr3103
pprr0304

Outputs:-

Code:
Missing files as
pprr0303
pprr0403
pprr0503
pprr0104
pprr0204


Last edited by zaxxon; 09-07-2012 at 08:24 AM.. Reason: code tags
# 2  
Old 09-07-2012
As per inputs, assuming you have the same file name..

Just change the month for other files..

Currently configured for 3rd month only..

Don't know how to use calender inside code right now..Smilie

Code:
for i in {01..31} #don't know how to work with calender dates. you can do it manually.. 
do
if [[ "$i" -lt "10" ]]
then
file="pprr0"$i"03" # Month - Change as 04, 05 and so on.
ls $file >/dev/null
    if [[ $? != 0 ]]
    then
    echo "$file is missing"
    fi
else

file="pprr"$i"03"
ls $file >/dev/null
    if [[ $? != 0 ]]
    then
    echo "$file is missing"
    fi
fi
done

# 3  
Old 09-07-2012
Avoiding leap year considerations, this might do what you expect:
Code:
ls  p*|sort -n -k1.7,1.8 -k1.5,1.6|
awk     'BEGIN {split("31 28 31 30 31 30 31 31 30 31 30 31", mdays)}

         function prtmiss (ld, ad, am) {for (i = ld+1; i < ad; i++) printf "pprr%02d%02d is missing\n", i, am}

        {day=substr($0,5,2)+0; mth=substr($0,7,2)+0;
         if (mth > prevm) {prtmiss(prevd, mdays[prevm]+1, prevm); prevd=0}
         prtmiss (prevd, day, mth);
         prevd=day; prevm=mth
        }'

It takes a sorted (!) directory listing, finds the gaps (actually the for loop doesn't start if there's no gap) and prints the missing files. For a new month, it prints the missing files until previous month's end (mdays +1) and the missing ones for the new month.

Last edited by RudiC; 09-07-2012 at 03:30 PM..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to list files in ascending order?

Hi, I need to list files in ascending order. Filenames are in format inpTDT_1, inpTDT_2, inpTDT_3 and so on. I want to list them in the ascending order based on the digit after underscore and send the output to a file. Please help (5 Replies)
Discussion started by: Neelkanth
5 Replies

2. Shell Programming and Scripting

Unable to list files in ascending order

Hi ! I am just trying to list my files in ascending order so that in some other software, I just want merge with some modification, when I list its coming like this new-10.txt new-11.txt new-12.txt new-13.txt new-14.txt new-15.txt new-16.txt new-17.txt new-18.txt new-19.txt... (2 Replies)
Discussion started by: nex_asp
2 Replies

3. Shell Programming and Scripting

How to takes the missing files?

Hi all , am using unix aix I have a files in one directory.. my files as in format qqss0607.ddd.. (06 is date 07 is month) how to check the missing dates .... can anyone tell me... (9 Replies)
Discussion started by: Venkatesh1
9 Replies

4. Shell Programming and Scripting

How to takes missing files

Hi Am using unix aix I have a group of files in File1 For ex:- Vi file1 A0405 A0605 A0805 When i tried using awk command am getting an error as No space a=`awk 'NF < 1 {next;} p && p != $1 { for( i = p; i < $1; i++ )print i; } {p = $1 + 1 }' file2` Error message:- + + awk NF <... (7 Replies)
Discussion started by: Venkatesh1
7 Replies

5. Shell Programming and Scripting

Help printing files in ascending order of the fi le size (in bytes)

Hey guys I'm new to unix and need help printing files in a specified directory according to size in bytes as well as files with equal bites in alphabetical order the part i have done so far prints out all files in the directory as well as setting a time limit in which they have been modified ... (2 Replies)
Discussion started by: wessy
2 Replies

6. Shell Programming and Scripting

Ascending order

How can I check if array is in ascending order? ---------- Post updated at 01:53 PM ---------- Previous update was at 01:25 PM ---------- Done it now (0 Replies)
Discussion started by: kristinu
0 Replies

7. UNIX for Advanced & Expert Users

merge two files in ascending order

Hello Friends, I want to merge two files in ascending order on the first field. And if the first field matches sort on 3rd field i.e, TXADDR should come ahead of RXADDR . file1 9 : TXADDR : 00000000 65 : TXDATA 0000000000000011 83 : TXDATA 0000000000000012 453 :... (10 Replies)
Discussion started by: user_prady
10 Replies

8. Shell Programming and Scripting

Ascending order within text

I appreciate all the help that I've already received but am running into one problem. I can find how to add something before a file with ascending numbers but not like this. I basically have a file that looks like this: 100 101 102 103 104 I need to add the following before each line with... (5 Replies)
Discussion started by: kerpm
5 Replies

9. UNIX for Advanced & Expert Users

Display modified files in ascending order

Hello, i want to display modified files in descending order. "ls -t" will display modified files in descending order. pls help. (1 Reply)
Discussion started by: balareddy
1 Replies

10. UNIX for Dummies Questions & Answers

Sort / ascending order

What's the command to sort a file in ascending order and redirect the output to another file? Thanks!!!!!! (1 Reply)
Discussion started by: gyik
1 Replies
Login or Register to Ask a Question