DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Shell Scripting (http://www.daniweb.com/forums/forum113.html)
-   -   How to delete the First 3 characters from File-name using unix command (http://www.daniweb.com/forums/thread151722.html)

babusek Oct 17th, 2008 7:37 am
How to delete the First 3 characters from File-name using unix command
 
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

noobguy Oct 17th, 2008 9:01 am
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.

babusek Oct 17th, 2008 10:02 am
Re: How to delete the First 3 characters from File-name using unix command
 
Quote:

Originally Posted by noobguy (Post 714673)
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

eggi Oct 19th, 2008 11:46 pm
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


All times are GMT -4. The time now is 1:52 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC