Home Man
Today's Posts

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Script for files

shell scripts

Login to Reply

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 11:43 AM.. 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.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Find and removing the old files and zipping the files using shell script venkat918 UNIX for Beginners Questions & Answers 6 04-24-2018 01:21 PM
Shell script for field wise record count for different Files .csv files Kirands Shell Programming and Scripting 14 01-21-2016 04:06 PM
Renaming multiple files in sftp server in a get files script jhilmil Shell Programming and Scripting 7 12-27-2014 04:16 AM
Bash script deleting my files, and editing files in subdirectories question TheGreatGizmo Shell Programming and Scripting 4 02-05-2014 06:37 PM
Read files in shell script code and run a C program on those files shoaibjameel123 Shell Programming and Scripting 2 09-17-2013 04:48 AM
Need to exclude .NFSxxx files in clear old files batch script kimberlyg2007 Shell Programming and Scripting 2 02-12-2013 05: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 07:14 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 09:34 AM
How to retrieve all the linked script files/ctl files/sql files? franksubramania Shell Programming and Scripting 1 05-04-2009 01: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 12:01 PM

All times are GMT -4. The time now is 10:10 PM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password