Picking up last two specific files, for transfer


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Picking up last two specific files, for transfer
# 15  
Old 06-27-2018
I know that you don't believe me yet, but about 299 cycles from now (when your numbers grow to 4 digits instead of 3 digits) you will find that your code stops working unless you pay attention to my suggestion...
Code:
D_file=`ls -1rt *Deposit_*.csv | tail -1`
Dd_file=`ls -1rt *Deposit_*.checksum | tail -1`
W_file=`ls -1rt *Withdrawal_*.csv | tail -1`
Ww_file=`ls -1rt *Withdrawal_*.checksum | tail -1`

I know you say you prefer tail over head, but your script will run faster if you use:
Code:
D_file=`ls -1t *Deposit_*.csv | head -1`
Dd_file=`ls -1t *Deposit_*.checksum | head -1`
W_file=`ls -1t *Withdrawal_*.csv | head -1`
Ww_file=`ls -1t *Withdrawal_*.checksum | head -1`

and on Solaris systems, you should get the same results without the -1 option (filtered either by head or by tail):
Code:
D_file=`ls -t *Deposit_*.csv | head -1`
Dd_file=`ls -t *Deposit_*.checksum | head -1`
W_file=`ls -t *Withdrawal_*.csv | head -1`
Ww_file=`ls -t *Withdrawal_*.checksum | head -1`

Note that the ls -1 option is on by default whenever standard output is not a terminal (and the pipe that is the standard output of ls when its output if fed to head or tail is not a terminal).

Last edited by Don Cragun; 06-27-2018 at 08:38 AM.. Reason: Add note.
This User Gave Thanks to Don Cragun For This Post:
# 16  
Old 06-27-2018
I have followed your suggestion, (using the head) and its working fine, thank you.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Picking up files conditionally

Hi I have a scenario: I have a directory say DIR1 (no sub directories) and have few files in that directory as given below: app-cnd-imp-20150820.txt app-cxyzm-imp-20150820.txt app-petco-imp-20150820.txt app-mobility-imp-20150820.txt app-mobility-imp-20150821.txt... (7 Replies)
Discussion started by: Saanvi1
7 Replies

2. Linux

How to transfer files...

Hi guys, ok so, how do you go about networking between Windows and Linux so that I can transfer files between each other? (5 Replies)
Discussion started by: billcrosby
5 Replies

3. UNIX for Dummies Questions & Answers

Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (12 Replies)
Discussion started by: robertbrown624
12 Replies

4. Shell Programming and Scripting

Urgent ...pls Sorting files based on timestamp and picking the latest file

Hi Friends, Newbie to shell scripting. Currently i have used the below to sort data based on filenames and datestamp $ printf '%s\n' *.dat* | sort -t. -k3,4 filename_1.dat.20120430.Z filename_2.dat.20120430.Z filename_3.dat.20120430.Z filename_1.dat.20120501.Z filename_2.dat.20120501.Z... (1 Reply)
Discussion started by: robertbrown624
1 Replies

5. Shell Programming and Scripting

Transfer Of Files

How to transfer the files in windows server to the unix server by using the unix or ftp commands? (1 Reply)
Discussion started by: vinay123
1 Replies

6. Shell Programming and Scripting

Copying specific files from remote m/c to specific folders

Hi All, I am trying to rsync some of the latest files from remote m/c to my local linux box. Folder structure in my remote m/c looks like this /pub/Nightly/Package/ROLL/WIN /pub/Nightly/Package/SOLL/sol /pub/Nightly/Package/SOLL/linux Each of the folder contains gzip files which on daily... (0 Replies)
Discussion started by: jhoomsharabi
0 Replies

7. UNIX for Dummies Questions & Answers

How to transfer files

please help me to transfer files from one server to another one i am having problem in it thanks (1 Reply)
Discussion started by: pankaj001np
1 Replies

8. UNIX for Dummies Questions & Answers

How to transfer files

(0 Replies)
Discussion started by: spoonman
0 Replies

9. Shell Programming and Scripting

transfer of specific file content to another file

What commands do you need to transfer a specfic portion of a file content to another file? eg file_one has 00012 10012 00013 10013 00014 10014 So I just want to transfer all the values of the second column ie 10012, 10013, 10014 to be transferred to file_two? Thanks in advance.... (1 Reply)
Discussion started by: mem101
1 Replies

10. UNIX for Advanced & Expert Users

How do i transfer files

Im trying to transfers a file from one unix server to another , make some changes and then send it back to the original server. All this using modems. I've been using "cu" and i can "get" the file but i can't "put" it. Besides I need to do this using a shell script. I can write a script to get... (4 Replies)
Discussion started by: phsoft
4 Replies
Login or Register to Ask a Question