Edit names of files in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Edit names of files in a directory
# 1  
Old 08-12-2013
Computer Edit names of files in a directory

Hi all,

I have a directory with multiple (thousnads) of files, which are named this way

Code:
ABCDEF.wo.im-1
OKRAME.ire.roi
IOJEAFO01.irt.gfg
IMNYBL05.REG.gkf


I would like to keep the part of the name (everything before the first dot in the filename).
The desired output:

Code:
ABCDEF
OKRAME
IOJEAFO01
IMNYBL05

I know I should be using `sed` for this, but I haven't used Linux for a while, some help would be appreciated.
Please feel free to assume any directory as an example "~$home/user"

Thanks all

Last edited by zaxxon; 08-12-2013 at 06:15 PM..
# 2  
Old 08-12-2013
Depending on your shell, you could do this also with Parameter Substitution.
What have you tried so far?
This User Gave Thanks to zaxxon For This Post:
# 3  
Old 08-12-2013
Try
Code:
for FILE in *; do echo mv $FILE ${FILE%%.*}; done

Should this exceed your LINE_MAX, try
Code:
ls * | while read FILE; do  echo mv $FILE ${FILE%%.*}; done

These 2 Users Gave Thanks to RudiC For This Post:
# 4  
Old 08-12-2013
I haven't tried stuff yet (cuz I am not sure how to start the command), been looking online for similar questions, found none yet. I am using a bash shell.

---------- Post updated at 10:05 AM ---------- Previous update was at 09:58 AM ----------

Quote:
Originally Posted by RudiC
Try
Code:
for FILE in *; do echo mv $FILE ${FILE%%.*}; done

Should this exceed your LINE_MAX, try
Code:
ls * | while read FILE; do  echo mv $FILE ${FILE%%.*}; done


Yes that worked Smilie, I should keep on revising what I know in Linux. Many Thanks mate Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies

2. Shell Programming and Scripting

Remove all files with specific file names in directory

If I have 5 files in a directory, what is the best way to remove specific files in it? For example, snps.ivg probes.ivg Desired output probes.ivg probes.txt all.txt Basically, removing those files with "snp" in the filename regardless of extension. Thank you :). (2 Replies)
Discussion started by: cmccabe
2 Replies

3. Shell Programming and Scripting

Finding files in directory with similar names

So, I have a directory tree that has many files named thusly: X_REVY.PDF I need to find any files that have the same X portion (which can be nearly anything) as any another file (in any directory) but have different Y portions (which can be any number from 1-99). I then need it to return... (3 Replies)
Discussion started by: Kamezero
3 Replies

4. Shell Programming and Scripting

How to find all files which has names in uppercase in a directory

i want to display all the files which has their names in the Uppercase in a particular directory...guide.. (6 Replies)
Discussion started by: sheelsadan
6 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. Shell Programming and Scripting

Comparing files names in directory over two servers

Hi folks I need to write a shell script to check whether source and the destination has the same files. The source and destination are over two servers and connecting through ssh. It should even compare the date i.e, the complete file name, date stamp and size should match. Should list out all the... (3 Replies)
Discussion started by: Olivia
3 Replies

7. Shell Programming and Scripting

How to store files names from a directory to an array

Hi I want to store the file names into an array. I have written like this but I am getting error. declare -A arr_Filenames ls -l *.log | set -A arr_Filenames $(awk '{print $9}') index=0 while (( $index < ${#arr_Filenames })); do Current_Filename=${arr_Filenames} ... (5 Replies)
Discussion started by: dgmm
5 Replies

8. UNIX for Dummies Questions & Answers

How can i copy a list of files with different names into others directory have the same name?

dear all. how can i copy a list of files with different names into others directory have the same name like i have 3 files 10_10 10_10_11 10_10_11_12 and i have 3 directories 10_10 10_10_11 10_10_11_12 how can i make a loop to cp this files into the directory have the same name like... (31 Replies)
Discussion started by: t17
31 Replies

9. Shell Programming and Scripting

how can i copy a list of files with different names into others directory have the same name

dear all. how can i copy a list of files with different names into others directory have the same name like i have 3 files 10_10 10_10_11 10_10_11_12 and i have 3 directories 10_10 10_10_11 10_10_11_12 how can i make a loop to cp this files into the directory have the same name like... (0 Replies)
Discussion started by: t17
0 Replies

10. Solaris

Not able to edit files present in mounted directory

I had mount from server A to server B. I am able to access the files present under server B. I can create new files on server B, but i am not able to edit the files which are already present. When i saw the permissions on those files it is 777. can some one tell me why i am not able to edit... (2 Replies)
Discussion started by: subbaraju
2 Replies
Login or Register to Ask a Question