Move file from one directory and update the list file once moved.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Move file from one directory and update the list file once moved.
# 8  
Old 03-01-2018
Dear RudiC,

I am confused from your above post.
Kindly guide
# 9  
Old 03-01-2018
What is the output of the proposal in post#3? Compare this to the original file. It should be the file names for which the mv failed.
This User Gave Thanks to RudiC For This Post:
# 10  
Old 03-01-2018
what if my file list its keep on appending.
so i want to read each line perform move command and then delete the line from the listfiles one by one simultaneously.

Last edited by sadique.manzar; 03-01-2018 at 04:58 PM..
# 11  
Old 03-01-2018
Appending? No way - if you run the snippet as given. I've (reluctantly) built your sceanrio from post#6 but removed file003.bin from the input file. Result:
Code:
while read line; do cp -v $line /tmp/; done <file 2>/dev/null | sed 's/\o047\| ->.*$//g; s/^/^/'  | grep -vxf- file
TEST/file003.bin

which - to me - is EXACTLY what you requested : the input file with ALL successful moves deleted. Save this result to a file and replace the input

You could also try - given the input is sorted -
Code:
while read line; do cp -v $line /tmp/; done <file 2>/dev/null | cut -d\' -f2 | comm -13 - file


Last edited by RudiC; 03-01-2018 at 04:40 AM..
This User Gave Thanks to RudiC For This Post:
# 12  
Old 03-01-2018
Sorry for the confusion.
what i mean to say is my input filelist is keep appending through a program.
What i need to do is move this files whose path has be captured in the filelist to another directory.
and once moved delete line from the filelist not file from the directory
# 13  
Old 03-01-2018
You say another process has the input filelist open for writing randomly and simultaneously? Then your request can't be fulfilled without implementing locking mechanisms, esp. in that other program. What you can do is keep your successes in an extra file, deduct / exclude those from the input file, and use the result for moving.
This User Gave Thanks to RudiC For This Post:
# 14  
Old 03-01-2018
Dear RudiC,

When I run your #post3 script.
files are moved but processedfile.txt still contains the lines, which i need to update after move.
Once succesfully moved, these lines should not be present in the processedfile.txt filelist.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script cannot create directory and move the file to that directory

I have a script, which is checking if file exists and move it to another directory if then mkdir -p ${LOCL_FILES_DIR}/cool_${Today}/monthly mv report_manual_alloc_rpt_A_I_ASSIGNMENT.${Today}*.csv ${LOCL_FILES_DIR}/cool_${Today}/monthly ... (9 Replies)
Discussion started by: digioleg54
9 Replies

2. Shell Programming and Scripting

List files with date, create directory, move to the created directory

Hi all, i have a folder, with tons of files containing as following, on /my/folder/jobs/ some_name_2016-01-17-22-38-58_some name_0_0.zip.done some_name_2016-01-17-22-40-30_some name_0_0.zip.done some_name_2016-01-17-22-48-50_some name_0_0.zip.done and these can be lots of similar files,... (6 Replies)
Discussion started by: charli1
6 Replies

3. Shell Programming and Scripting

Move file in to directory- script

Hi In directory /mnt/upload I have about 100 000 files (*.png) that have been created during the last six months. Now I need to move them to right folders. eg: file created on 2014-10-10 move to directory /mnt/upload/20141010 file created on 2014-11-11 move to directory /mnt/upload/20141111... (6 Replies)
Discussion started by: primo102
6 Replies

4. Shell Programming and Scripting

Shell script to get the latest file from the file list and move

Hi, Anybody help me to write a Shell Script Get the latest file from the file list based on created and then move to the target directory. Tried with the following script: got error. A=$(ls -1dt $(find "cveit/local_ftp/reflash-parts" -type f -daystart -mtime -$dateoffset) | head... (2 Replies)
Discussion started by: saravan_an
2 Replies

5. Shell Programming and Scripting

How to create a log file that simply shows the name of a file and what directory it was moved to.

Newbie...Thank you for your help. I am creating my first script that simply generates subdirectories to organize video, music, and text files within those subdirectories from my current working directory. PROBLEM: I am trying to write a log file that contains, for each file, the original file... (0 Replies)
Discussion started by: BartleDoo
0 Replies

6. Shell Programming and Scripting

temporary file to file then move to directory

Ok in my bash script i have 5 options to create a simple html script. I need to create a temporary file and whatever the user types will be stored in that file using html codes. And then I have another option in which that temporary file will be moved to the public_html directory in which the user... (19 Replies)
Discussion started by: gangsta
19 Replies

7. Shell Programming and Scripting

Move the latest or older File from one directory to another Directory

I Need help for one requirement, I want to move the latest/Older file in the folder to another file. File have the datetimestamp in postfix. Example: Source Directory : \a destination Directory : \a\b File1 : xy_MMDDYYYYHHMM.txt (xy_032120101456.txt) File2: xy_MMDDYYYYHHMM.txt... (1 Reply)
Discussion started by: pp_ayyanar
1 Replies

8. Shell Programming and Scripting

A script that will move a file to a directory with the same name and then rename that file

Hello all. I am new to this forum (and somewhat new to UNIX / LINUX - I started using ubuntu 1 year ago).:b: I have the following problem that I have not been able to figure out how to take care of and I was wondering if anyone could help me out.:confused: I have all of my music stored in... (7 Replies)
Discussion started by: marcozd
7 Replies

9. Shell Programming and Scripting

List moved files in text file

Hi. I am actually doing all of this on OSX, but using unix apps and script. I have built my own transparent rsync/open directory/mobility/etc set of scripts for the firm I work at, and it is all almost complete except for ONE THING. I have the classic problem with rsync where if a user... (0 Replies)
Discussion started by: Ashtefere
0 Replies

10. Shell Programming and Scripting

Move a file from windows directory to unix directory

Move a file from windows directory to unix directory, is this possible? if it is, can someone help me on this? Thanks! God bless! (1 Reply)
Discussion started by: kingpeejay
1 Replies
Login or Register to Ask a Question