sorting file names with hyphen and underscore


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sorting file names with hyphen and underscore
# 1  
Old 04-13-2012
sorting file names with hyphen and underscore

Hi,

I have two types of file names

filename1_12345 or filename1-12345 at the same time I have second type
filename2-12345 in a txt file.

I am trying to write awk script that will sort these names with below pattern


ALL file names like
filename1_12345 and filename1-12345 will go to folder1 (lets say same directory)
filename1_23451and filenmae1_23451 will go to folder2

filename1_34512 and filename1_34512 will go to folder 3

till 9

and rest all filename2- whaterever will go to folder-temp


all the these files are listed in a txt file and I can use move command to move.

can you please give me a direction to sort for numbers.
# 2  
Old 04-13-2012
Code:
awk -F '[-_]'  '/$1 ~ 2$/ {print "mv", $0, "./folder-temp/" $0; next}
                   { where=substr($1,length($1)-1,1); where="./folder" where;
                      print "mv", $0, where "/" $0} 
                   ' inputfile > shell.sh
# visually check the file
more shell.sh

If shell.sh looks good make it runnable, then run it:
Code:
chmod +x shell.sh
./shell.sh

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace a space with underscore in a file

i have a file with following data. { EqName "Tan 1" .... .... } { EqName "Sin 2" ... ... } I have to replace the value of EqName to Tan_1 and Sin_2 in file.Can i use sed or awk ? cat file|grep EqName|awk '{print $2 $3}'|sed -i 's//_/g' I tried with this but it... (2 Replies)
Discussion started by: Jag02
2 Replies

2. Shell Programming and Scripting

Sorting a column according to the number of names

Hey, So I'm having issues sorting a data set. The data set contains entries as such; # key: sex, time, athlete, athlete's nationality, date, city, country M, 2:30:57.6, Harry Payne, GBR, 1929-07-05, Stamford Bridge, England M, 2:5:42, Khalid Khannouchi, MAR, 1999-10-24, Chicago, USA M,... (1 Reply)
Discussion started by: DNM_UKN
1 Replies

3. Shell Programming and Scripting

Bash to rename file after second occurence of underscore

I am trying to use bash to remove the text in all filenames after the second _ in specific files that end in .bam or .vcf. However the bash errors looking for the files in the directory. Thank you :). files in directory ... (4 Replies)
Discussion started by: cmccabe
4 Replies

4. Shell Programming and Scripting

Exclude certain file names while selectingData files coming in different names in a file name called

Data files coming in different names in a file name called process.txt. 1. shipments_yyyymmdd.gz 2 Order_yyyymmdd.gz 3. Invoice_yyyymmdd.gz 4. globalorder_yyyymmdd.gz The process needs to discard all the below files and only process two of the 4 file names available ... (1 Reply)
Discussion started by: dsravanam
1 Replies

5. Shell Programming and Scripting

Sorting file based on names

Hi I have some files in directory and the names of files are like jnhld_15233_2010-11-23 jnhld_15233_2007-10-01 jnhld_15233_2001-05-04 jnhld_15233_2011-11-11 jnhld_15233_2005-06-07 jnhld_15233_2000-04-01 ..etc How can i sort these files based on the date in the file name so that ... (4 Replies)
Discussion started by: morbid_angel
4 Replies

6. Shell Programming and Scripting

ksh function getopts get leading underscore unless preceded by hyphen

If I call my function with grouped options: "logm -TDIWEFO 'message' ", then only the "T" gets parsed correctly. The subsequent values returned have underscores prefixed to the value: "_D", "_I", etc. If I "logm -T -DIWEFO 'message' ", the "T" and the "D" are OK, but "I" through "O" get the... (2 Replies)
Discussion started by: kchriste
2 Replies

7. Shell Programming and Scripting

Not able to create any file name start with "-" hyphen in Solaris

Hi All, I am not able to create any file name start with "-" hyphen. Any logical issue with these types of files creation in Solaris. ============================== bash-3.00$ touch -file.txt touch: illegal option -- i usage: touch file... touch ] file... touch ... (5 Replies)
Discussion started by: hanu_oracle
5 Replies

8. Shell Programming and Scripting

Searching for file names in a directory while ignoring certain file names

Sun Solaris Unix Question Haven't been able to find any solution for this situation. Let's just say the file names listed below exist in a directory. I want the find command to find all files in this directory but at the same time I want to eliminate certain file names or files with certain... (2 Replies)
Discussion started by: 2reperry
2 Replies

9. Shell Programming and Scripting

sorting names after doing a find

hi all, is there an easy way in ksh to sort the results of a find in say alphabetical order ?? e.g in my script i am doing a find for all servers find . -name "server.xml" and the output is not in any order. thanks in advance. (4 Replies)
Discussion started by: cesarNZ
4 Replies

10. Shell Programming and Scripting

Finding & Moving Oldest File by Parsing/Sorting Date Info in File Names

I'm trying to write a script that will look in an /exports folder for the oldest export file and move it to a /staging folder. "Oldest" in this case is actually determined by date information embedded in the file names themselves. Also, the script should only move a file from /exports to... (6 Replies)
Discussion started by: nikosey
6 Replies
Login or Register to Ask a Question