How to remove first few characters from multiple file names without do loop?


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers How to remove first few characters from multiple file names without do loop?
# 1  
Old 11-19-2013
How to remove first few characters from multiple file names without do loop?

Hi Fellows,

I was wondering how I can remove first few characters from multiple file names without do loop in unix?

e.g.

Code:
water123.xyz
water456.xyz

to

Code:
123.xyz
456.xyz

Thanks

Paul


Thanks.

Last edited by radoulov; 11-19-2013 at 05:16 PM..
# 2  
Old 11-19-2013
You can try this:
Code:
ls water* | perl -nle '$x=$_;s/^water//;system "mv $x $_"'

# 3  
Old 11-19-2013
Why not a loop? How will you process each file without it? There is a perl utility called rename that comes standard on many Linux systems.

Code:
mute@thedoctor:~/temp/paul_moghadam$ ls
water123.xyz  water456.xyz
mute@thedoctor:~/temp/paul_moghadam$ rename 's/water//' water*
mute@thedoctor:~/temp/paul_moghadam$ ls
123.xyz  456.xyz

# 4  
Old 11-19-2013
Thanks very much
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File names with international characters in not getting recognized in Linux server

Hi, I am using image Magick for resizing the images. Everything is working as long as the file names are in English. But when the file names are in European accented fonts like sólido_sitzbezüge_textil_in_design.jpg stándard_gris_thorium_tallisé.jpg NOIR_MÉTALLISÉ.jpg the program is skipping... (7 Replies)
Discussion started by: Merlin Joseph
7 Replies

2. Shell Programming and Scripting

Trying to do multiple dir's and multiple file names etc.

What am I missing? find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing conjunction find: 0652-009 There is a missing... (3 Replies)
Discussion started by: xgringo
3 Replies

3. UNIX for Dummies Questions & Answers

[solved]removing characters from a mass of file names

I found a closed thread that helped quite a bit. I tried adding the URL, but I can't because I don't have enough points... ? Modifying the syntax to remove ! ~ find . -type f -name '*~\!]*' | while IFS= read -r; do mv -- "$REPLY" "${REPLY//~\!]}"; done These messages are... (2 Replies)
Discussion started by: rabidphilbrick
2 Replies

4. Tips and Tutorials

How to manage file names with special characters

One of the common questions asked are: how do i remove/move/rename files with special (non-printable) characters in their name? "Special" doesn't always mean the same. As there are more and less special characters, some solutions are presented, ranging from simple to very complicated. Usually a... (0 Replies)
Discussion started by: bakunin
0 Replies

5. Shell Programming and Scripting

Finding File Names Ending In 3 Random Numerical Characters

Hi, I have a series of files (upwards of 500) the filename format is as follows CC10-1234P1999.WGS84.p190 each of this files is in a directory named for the file but excluding the extension. Now the last three numeric characters, in this case 999, can be anything from 001 to 999, I need to... (3 Replies)
Discussion started by: roche.j.mike
3 Replies

6. UNIX for Dummies Questions & Answers

How to remove characters from multiple .txt files

Friends, I want to remove charecters from multiple .txt files. Foe example : In this .txt files there are many "ctrl m" present in last of each line in one .txt file. I want to remove "ctrl m" from each line from all .txt files. Need your help regarding this. (4 Replies)
Discussion started by: meetsubhas
4 Replies

7. UNIX for Dummies Questions & Answers

Listing full file names with the exact length of 3 characters

This is what I have to do: Display the full file name (including the full path) and file size of all files whose name (excluding the path) is exactly 3 characters long. This is the code I have: find / -printf "Name: %f Path: %h Size: %s (bytes)\n" 2>/dev/null | grep -E "Name: .{3,} Path" |... (7 Replies)
Discussion started by: Joesgrrrl
7 Replies

8. Shell Programming and Scripting

Weird Ascii characters in file names

Hi. I have files in my OS that has weird file names with not-conventional ascii characters. I would like to run them but I can't refer them. I know the ascii # of the problematic characters. I can't change their name since it belongs to a 3rd party program... but I want to run it. is there... (2 Replies)
Discussion started by: yamsin789
2 Replies

9. Shell Programming and Scripting

Replace characters in all file names in a particular directory

Hi, I have searched the forum on how to mass replace the file names. We are doing the migration and I am trying to accomplish a task where I have to replace all UNIX scripts in a particular directory that start with bdw to fdm... For example: bdw0110137.sh should be fdm0110137.sh Keep the... (4 Replies)
Discussion started by: madhunk
4 Replies

10. Shell Programming and Scripting

remove multiple characters once

i have a variable in a bash shell script called $hostname. $hostname will always be different except it will always start with "-s " that is a - an s and a space. so echo $hostname will look like this: -s somehostname.com how can i get rid of the leading -s ? ive tried tr -d but that gets... (2 Replies)
Discussion started by: norsk hedensk
2 Replies
Login or Register to Ask a Question