How to look for the last file and rename it (sequencially, increment by one)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to look for the last file and rename it (sequencially, increment by one)
# 1  
Old 02-15-2010
How to look for the last file and rename it (sequencially, increment by one)

I need to Ftp a file to a UNIX directory from a windows directory, the file needs to be put sequencially in the UNIX directory , for example: I get the file from the windows directory with the following name.
EFT###.DAT, the script needs to look in the UNIX directory and if there are files, for example: eft710.dat, eft711.dat,eft712.dat. The new file that I just ftp needs to be rename as a eft713.dat keep incrementing by one.
Thank you in advance
# 2  
Old 02-15-2010
Can the files arrive on the unix system from more than one source? If not, maintain a serial number file on the Windows system, and increment it with each transfer.
If there is a small number of sources, use a separate directory for each source.
Alternatively, if the files do not arrive more frequently than 1 a minute, use a different naming convention that ensures no duplicates, and periodically move the files from the receiving directory to a processing directory, and at this stage rename the files.
# 3  
Old 02-15-2010
Question Who is doing the ftp?

Is the ftp program on Windows or Unix? The answer may push you towards a path to solution.

Or, are you simply looking for a unix script to handle the rename of a file? For instance, ftp receive a file called my_new.dat that you want to rename to the next available sequential file number in pattern EFT###.dat
# 4  
Old 02-15-2010
Answer

Quote:
Originally Posted by joeyg
Is the ftp program on Windows or Unix? The answer may push you towards a path to solution.

Or, are you simply looking for a unix script to handle the rename of a file? For instance, ftp receive a file called my_new.dat that you want to rename to the next available sequential file number in pattern EFT###.dat


---------- Post updated at 10:50 AM ---------- Previous update was at 10:43 AM ----------

I've made two scripts.

First script is for ftp command in msdos, it's for get a filelist from the unix ftp server

---------- Post updated at 10:51 AM ---------- Previous update was at 10:50 AM ----------

comandos.ftp
Code:
open 192.168.253.7
user cnavarro |nC*d3W3
ls
bye

you muste execute with
C:\ftp -n -s:comandos.ftp > ftp.out

---------- Post updated at 10:54 AM ---------- Previous update was at 10:51 AM ----------

This generates ftp.out file, and must be "analyzed" for getting max id of files. For this I've created second file script

script.awk
Code:
/eft[0-9]*\.dat/{
    match($0,/[0-9]+/)
    n=0+substr($0,RSTART,RLENGTH)
    if (n>max){
        print n" es mayor que "max
        max=n
    }
}
END{
    print "open 192.168.253.7" > "upFile.ftp"
    print "user usuario password" > "upFile.ftp"
    print "put arch1 eft"(max+1)".dat" > "upFile.ftp"
    print "bye" > "upFile.ftp"
}

you must execute with:
c:\gawk --posix -f script.awk ftp.out

This generates a second ftp file you must run with:
C:\ftp -n -s:upFile.ftp > ftp.out


Sorry for multiedit but I can't post a reply, can anybody help me?

Last edited by kcoder24; 02-15-2010 at 12:56 PM.. Reason: I can't post
# 5  
Old 02-15-2010
Quote:
Sorry for multiedit but I can't post a reply, can anybody help me?
I've noticed that you cannot create two sequential posts. The second post is appended to the first and separated with a "post updated line"

You solution works, as long as there is a reasonable time gap between transmissions.
# 6  
Old 02-15-2010
Quote:
Originally Posted by jgt
I've noticed that you cannot create two sequential posts. The second post is appended to the first and separated with a "post updated line"

You solution works, as long as there is a reasonable time gap between transmissions.


---------- Post updated at 11:20 AM ---------- Previous update was at 11:20 AM ----------

Good point, when I did it I just think in a static environment, and you propose a dynamic environment.

About my posts, if I press "Post reply" I write my message but it says is too short, even if I wrote more than 100 chars. I'm having a problem with vBulletin think because this is no the only forum where I face the problem, and the repetead factor is vBulletin.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need a REGEX to increment the file number of a pdf file

Hello, I have a few thousand .pdf files in various folders each have a naming scheme like this: 006_-_Titled_Document_#34_-_September-25-2011-side-1.pdf In each folder, the number system starts at 001 (as you see on the far left of the file name), and then ends at 999 (maximum .pdf files).... (4 Replies)
Discussion started by: Marcus Aurelius
4 Replies

2. Shell Programming and Scripting

Increment value in text file

Hi Guys, I am new to shell programing, I have a csv file which has 50k records and I have got the requirement to increment the value in second column after each 5000 records. for example below A,B,C,D //Header 1,1,London,UK 1,1,Manchester,UK 1,1,Glasgow,UK . . . 1,1,Newyork,USA... (7 Replies)
Discussion started by: rizzu1555
7 Replies

3. Shell Programming and Scripting

Need to increment number in data file

Hello, I have an Excel spreadsheet with the following data: Refntns3_1 char 30 Ref H77 nt codon 1 Reference H77 Nucleotide Codon 1 -- Codns3_1 char 30 Obs Nucleotides codon 1 Observed Nucleotides Codon 1 ... (2 Replies)
Discussion started by: deneuve01
2 Replies

4. Shell Programming and Scripting

Increment Numbers in File

Hello, I have a text file withe some records 20121031|5 20121030|3 20121029|1 20121028|4 20121027|6 I want to search for a patten with '20121030' and then increment the second part of the delimiter i.e. 3 by 1 to make it 4 to look like 20121031|5 20121030|4 20121029|1 20121028|4... (7 Replies)
Discussion started by: pparthiv
7 Replies

5. Shell Programming and Scripting

To increment the values from the file

Hi I have the file called "file.txt" which contains the following output $cat file.txt sandy <version>1</version> karen <version>2</version> Rob <version>3</version> peter <version>4</version> i want to write a command which will add the value 1 to the digits and show the output... (2 Replies)
Discussion started by: sidh_arth85
2 Replies

6. Shell Programming and Scripting

Increment a value in a configuration file.

Experts, I would appreciate if someone took the time to express there opinion /approach in creating a new change daily to a configuration file. I create a new log file each day and I wish to have a browser based reader display the new file. To achieve this I would need to create a new... (2 Replies)
Discussion started by: jaysunn
2 Replies

7. Shell Programming and Scripting

File existence and increment

count=0; while read line; do ] && let count=count+1; done < file_name.txt echo echo "$count of 10 files found " echo The scenario is a follows : I have a file which contains a list of filenames present in particular directory . I am checking fo the existence of the file and... (5 Replies)
Discussion started by: ultimatix
5 Replies

8. Shell Programming and Scripting

Check file and increment

My scripts excepts 4 files ABCD_01 ABCD_02 ABCD_03 ABCD_04 I want to check for these files , and increment counter one by one . at the end i would like to echo as 4 of 4 expected instances of file found . I tried something like thsi $counter =1 if counter=counter+1 i need... (5 Replies)
Discussion started by: ultimatix
5 Replies

9. Shell Programming and Scripting

Rename a file sequencially in UNIX

I need to be able to look for the last file in a dirctory in UNIX, the file satrt with EFT so this work file=$(ls -tr $EFT*.dat | tail -1) # Select the latest file my last file is EFT1234.dat then I need to be able to get a file that I just ftp and rename with this name EFT1234.dat but... (5 Replies)
Discussion started by: rechever
5 Replies

10. Shell Programming and Scripting

Increment userid in file

Hello, does anyone know how to increment a userid(number) written in any scripting language that works on a shell? For example: I have a HTML file in this format: userid: name: telephone: Every time I execute my script it adds the same fields, except with the userid incremented. Like... (2 Replies)
Discussion started by: dejavu88
2 Replies
Login or Register to Ask a Question