Discover unique names and organize

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Discover unique names and organize
# 1  
Old 12-09-2013
Discover unique names and organize

I'm attempting to write a script that will look into a directory, discover all unique names, create directories for their prefix names and place the files inside. I do this now one by one with a simple script but I'd like to automate the process.

The directory would contain something like:
rv0050_v01.1002.dpx ...
rv0060_v01.1002.dpx ...
rv0090_v01.1002.dpx ...

So, I need to discover each unique name, create directories for only the prefix (rv0050,) and place the files inside.

Currently I use something like this:
   mkdir $dir ; mv $dir*.* $dir

# 2  
Old 12-10-2013
#! /bin/bash

for x in rv*
    [ ! -d $dir ] && mkdir $dir
    mv $x $dir/

# 3  
Old 12-10-2013
If run as written it creates a dir called "rv*" and nothing else.
Shouldn't "rv*" be $1?

Thank you
# 4  
Old 12-10-2013
No, a $1 takes the first input parameter.

What may be missing is some command to tell the script to list out the files?

Are you sure there are files that being with rv in the directory you are running the script form?

Last edited by joeyg; 12-10-2013 at 05:22 PM.. Reason: Clarified
# 5  
Old 12-10-2013
Looks like there are no files that match rv*. Your working directory may be some other than the one with the rv* files. Did you consider a cd to that directory?
# 6  
Old 12-11-2013
Ah, this does work. I altered it for use with all sorts of files.
for x in $1*
    [ ! -d $dir ] && mkdir $dir
    mv $x $dir/

# 7  
Old 12-11-2013
A more robust variant that can take the directory as parameter:
if [ -n "$1" ]
  cd "$1" || exit
for file in $mask
  [ -f "$file" ] || continue
  [ "$dir" != "$prevdir" ] && mkdir -p "$dir"
  mv "$file" "$dir"/

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Organize output with awk

Hello, maybe someone could help me with this. I'm trying to print in a more ordered way this input. the input file is: AB XY UT ZW PRAT 0 3 4 7214800 93 0 3 4 730770 ... (8 Replies)
Discussion started by: Ophiuchus
8 Replies

2. UNIX for Beginners Questions & Answers

sed awk: split a large file to unique file names

Dear Users, Appreciate your help if you could help me with splitting a large file > 1 million lines with sed or awk. below is the text in the file input file.txt scaffold1 928 929 C/T + scaffold1 942 943 G/C + scaffold1 959 960 C/T +... (6 Replies)
Discussion started by: kapr0001
6 Replies

3. Shell Programming and Scripting

Is there a way to organize bash_profile across different platforms

I want to have one .bash_profile works on multiple platform, ubuntu, debian, redhat, cygwin, osx. So how should I organize .bash_profile? It can be multiple files in some subdir Let me brief you: what i want is a way to organize bash_profile across platforms so I can use one set of profiles... (2 Replies)
Discussion started by: John_Peter
2 Replies

4. Shell Programming and Scripting

Print unique names in a specific column using awk

Is it possible to modify file like this. 1. Remove all the duplicate names in a define column i.e 4th col 2. Count the no.of unique names separated by ";" and print as a 5th col thanx in advance!! Q input c1 30 3 Eh2 c10 96 3 Frp c41 396 3 Ua5;Lop;Kol;Kol c62 2 30 Fmp;Fmp;Fmp ... (5 Replies)
Discussion started by: quincyjones
5 Replies

5. Shell Programming and Scripting

Print unique names in each row of a specific column using awk

Is it possible to remove redundant names in the 4th column? input cqWE 100 200 singapore;singapore AZO 300 400 brazil;america;germany;ireland;germany .... .... output cqWE 100 200 singapore AZO 300 400 brazil;america;germany;ireland (4 Replies)
Discussion started by: quincyjones
4 Replies

6. Shell Programming and Scripting

Change unique file names into new unique filenames

I have 84 files with the following names splitseqs.1, spliseqs.2 etc. and I want to change the .number to a unique filename. E.g. change splitseqs.1 into splitseqs.7114_1#24 and change spliseqs.2 into splitseqs.7067_2#4 So all the current file names are unique, so are the new file names.... (1 Reply)
Discussion started by: avonm
1 Replies

7. Shell Programming and Scripting

need help for a script to organize data

Hey all, I have a file with info like this 12:05:44 DEV001 (15F6) 71 5 1372 131 58 100 6 0 17 DEV002 (15FA) 60 0 928 15 50 N/A 2 N/A 5 DEV003 (15FE) 77 2 961 59 51 100 1 0 2... (2 Replies)
Discussion started by: leo.maveriick
2 Replies

8. UNIX and Linux Applications

Organize (pretty) code

I'm looking for terminal programs, which organize and pretty code like HTML or JavaScript. Thanks! ---------- Post updated at 07:01 AM ---------- Previous update was at 01:49 AM ---------- Found this Online javascript beautifier (1 Reply)
Discussion started by: borobudur
1 Replies

9. Shell Programming and Scripting

Organize of Data

Hello Expert, I am new in awk. I would like to know how to arrange data like Input File: lpar1 1 2 3 4 5 6 lpar10 4 5 6 lpar3 4 5 (3 Replies)
Discussion started by: shah09
3 Replies

10. UNIX for Dummies Questions & Answers

Get List of Unique File Names

I have a large directory of web pages. I am doing a search through the web pages using grep and would like to get a list of unique file names of search results. The following command works fine to give me a list of file names where term appears: grep -l term *.html However, since these are... (3 Replies)
Discussion started by: rjulich
3 Replies
Login or Register to Ask a Question