I want to move files from directory A to directory B. But there are some conditions.directory A structure:a.txt_20170502 b.txt_20170502a.txt_20170507asd.txt_20170509asd.txt_20170522So, I want to rename a.txt_20170502 to a.txt and move that file to directory B, but if a.txt is  present in directory B, it will not move that file.Example:a.txtasd.txtThis process continue until all the candidate files are moved from directory A to B.I am confused how I can check if files are already in that directory,It will not move that file.Condition :-There is another script running in background which will fetching data from directory B.So, if any files are present in directory B , it will be automatically copied mainframe server.
move only uniq files from one directory to other
shell script;ksh;file copy;mv
for file in A/*.txt_*; do  newfile=B/${file##*/}  # remove A path, add B path  newfile=${newfile%_*}  # remove trailing suffix  if [[ ! -f $newfile ]]; then    mv $file $newfile  fidoneThis will iterate over all files in A that matches *.txt_*. It will construct a new file path by replacing the A path with the B path and strip the trailing _xxxxxxxx suffix from the filename.  If the new filename is not already present under B, the file will be moved there.