943,949 Members | Top Members by Rank

Ad:
Oct 17th, 2008
0

How to delete the First 3 characters from File-name using unix command

Expand Post »
HI Folks
This is Question seems like scrap but look into this ..

I have several files in a directory(Ex:c:\dir\) now i have to remove the First 3 Characters from the File names in that directory. Using any unix command ..
Test Case 1:

C:\dir\
123file.txt
456newfile.mp3
57575unixfile.dat
trarruniing.txt

After the OPeration
now the Directory (c:\dir\) Should Contain
file.txt
newfile.mp3
unixfile.dat
trarruniing.txt
-----------------------------------------Thanks-----------------------------------------------------




Thanks
Last edited by babusek; Oct 17th, 2008 at 7:38 am.
Reputation Points: 10
Solved Threads: 1
Light Poster
babusek is offline Offline
28 posts
since Oct 2008
Oct 17th, 2008
0

Re: How to delete the First 3 characters from File-name using unix command

Look at cut or awk or sed either of those would do it for you.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
noobguy is offline Offline
6 posts
since Oct 2008
Oct 17th, 2008
0

Re: How to delete the First 3 characters from File-name using unix command

Click to Expand / Collapse  Quote originally posted by noobguy ...
Look at cut or awk or sed either of those would do it for you.
Thank q,

see this code : sed 's/...\(.*\)//' file.txt

can change the file-names from a .txt file.
but i want to the Directory Files
Reputation Points: 10
Solved Threads: 1
Light Poster
babusek is offline Offline
28 posts
since Oct 2008
Oct 19th, 2008
0

Re: How to delete the First 3 characters from File-name using unix command

Hey there,

If you want to do these en masse, you can either cd to the directory, or use a full path name and then apply that code generically to all the files in a for loop, while loop or using xargs, etc. That way your filename would be $x (or whatever you want to call your iterative variable) and not specifically the name of one file.

Hope that helps

, Mike
Reputation Points: 102
Solved Threads: 47
Posting Whiz
eggi is offline Offline
399 posts
since Oct 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Bash script to copy back up's
Next Thread in Shell Scripting Forum Timeline: fields with spaces





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC