👤
Home Man
Search
Today's Posts
Register

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

👤 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
Code:
PTP03-ban-end03.tar
PTP21-can-end03.tar
PTP21-moc-end03.tar
PTP21-moc-end03.tar
PTP21-can-end03.tar
PTP21-can-end03.tar

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
Code:
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
How to create or convert to pdf files from csv files using shell script? ssk250 Shell Programming and Scripting 2 10-14-2014 10:14 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
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 09:55 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


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

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
×
UNIX.COM Login
Username:
Password:  
Show Password





Not a Forum Member?
Forgot Password?