Script for files

shell scripts

Thread Tools Search this Thread
# 1  
Old 04-23-2018
Script for files

In a directory below tar files are there, the value between first and second delimiter(-) indicates
store name
i,e "ban", "can", "tan" etc are store names

i want to retain only one tar file per store in my current directory and move the remaining tar files to Temp directory
so in this case for stores "moc", "can" we have more than one tar file
so for stores "moc", "can" the tar file which got created first should be retained in current dicrectory and remaining
files should be moved to temp directory

Last edited by Scrutinizer; 04-23-2018 at 12:43 PM.. Reason: code tags
# 2  
Old 04-23-2018
ls -1tr *.tar | awk -F- 'store[$2]++' | while read file ; do echo mv $file temp_directory ; done

test first. if desired files to move are shown, remove echo and run again.
# 3  
Old 04-23-2018
Please be aware that NO two or more files with the same, identical name can exist an a directory. So the sample data given are not representative. Still, if the names' structure persists, rdrtx1's proposal will work as desired.

Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Find and removing the old files and zipping the files using shell script venkat918 UNIX for Beginners Questions & Answers 6 04-24-2018 02:21 PM
Shell script for field wise record count for different Files .csv files Kirands Shell Programming and Scripting 14 01-21-2016 05:06 PM
Renaming multiple files in sftp server in a get files script jhilmil Shell Programming and Scripting 7 12-27-2014 05:16 AM
How to create or convert to pdf files from csv files using shell script? ssk250 Shell Programming and Scripting 2 10-14-2014 11:14 AM
Bash script deleting my files, and editing files in subdirectories question TheGreatGizmo Shell Programming and Scripting 4 02-05-2014 07:37 PM
Script to unzip files and Rename the Output-files pmkenya Shell Programming and Scripting 2 11-20-2013 08:57 PM
Read files in shell script code and run a C program on those files shoaibjameel123 Shell Programming and Scripting 2 09-17-2013 05:48 AM
Need to exclude .NFSxxx files in clear old files batch script kimberlyg2007 Shell Programming and Scripting 2 02-12-2013 06:26 AM
need a shell script to extract the files from source file and check whether those files existonserve muraliinfy04 Shell Programming and Scripting 13 02-22-2012 08:14 AM
Need help creating a script to FTP files to a server and then delete the files that were transfered. jmalfhs Shell Programming and Scripting 4 01-18-2012 10:55 AM
Files copying - [ Listed files alone. ] - Shell script linuxadmin Shell Programming and Scripting 4 07-31-2011 09:45 AM
Help - Bug: A script to compile two types of data files into two temporary files ilove2smoke Shell Programming and Scripting 3 12-21-2009 10:34 AM
perl script for listing files and mailing the all files Shell Programming and Scripting 1 08-12-2009 10:04 AM
How to retrieve all the linked script files/ctl files/sql files? franksubramania Shell Programming and Scripting 1 05-04-2009 02:47 PM
I need a script to find socials in files and output a list of those files NewSolarisAdmin Shell Programming and Scripting 1 02-19-2009 01:01 PM