Add 0 in start of filename


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Add 0 in start of filename
# 15  
Old 04-09-2013
Blade

How about this
Code:
for i in `ls [0-9]-*.txt`
do
mv "$i" "0${i}"
done

This User Gave Thanks to pravin27 For This Post:
# 16  
Old 04-09-2013
Quote:
Originally Posted by pravin27
How about this
Code:
for i in `ls [0-9]-*.txt`
do
mv "$i" "0${i}"
done

It is doing

Code:
mv 4-track4.txt 04-track4.txt
mv 5-track5.txt 05-track5.txt

But now i need reverse.

Code:
04-track4.txt to 4-track4.txt
05-track5.txt to  5-track5.txt

---------- Post updated at 03:28 AM ---------- Previous update was at 03:26 AM ----------

Please confirm below code is fine?

Code:
for i in `ls [0-9]-*.txt`
do
#echo mv "$i" "0${i}"
echo mv  "0${i}" "$i"
done

# 17  
Old 04-09-2013
This is getting silly... You have been given all the needed information to do what is asked so I am closing the thread, if you reoppen again a new thread on the subject I will get angry...
Once given a solution, we here understand you will be testing it completely and ask again if there are doubts in your understanding on what is going on, e.g. you changed some parameters to see if you understood and are in mesure to say what you expected but did not produce...
Why dont you test your code yourself then ask what is wrong if you cant sort it out yourself, the way you are using the forum gives to the public the very strong impression you are not willing to learn, therefore why should we bother loosing our time here?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Add part of directory name to filename

Hello, I need to add a part of folder name to the files inside it. For instance the file is HMCBackup_20150430.155027.tgz and it is under directory /nim/dr/HMCBackup/cops22 I need to add cops22 to the file name so as it would be cops22_HMCBackup_20150430.155027.tgz Any help in doing... (10 Replies)
Discussion started by: hasn318
10 Replies

2. Shell Programming and Scripting

How to add a datetime stamp at a particular position in a filename?

hi, i have some files in a directory say abc.txt def.txt ghi.txt i am storing these file names in a temp file. ls -l | grep "^-" | awk '{print $NF}' > temp_file$$ i want to add a date time stamp at a particular place in the file names. it can be 1) before the extension... (2 Replies)
Discussion started by: Little
2 Replies

3. Shell Programming and Scripting

Script to add extension to filename

Hi all, I have a folder with a bunch of files in them, and I would like to add an extension (.mp3)to all these filenames. The folder has only files that I'd like .mp3 added to. It looks something like this: Intput: File1 File2 File3Output: File1.mp3 File2.mp3 File3.mp3Thanks in... (2 Replies)
Discussion started by: repiv
2 Replies

4. Shell Programming and Scripting

How to add filepath to filename when moving it?

Hi I have a cron job setup that searches for 'core dump' files in a fixed set of directories and moves the core files to a separate file system. I am able to add date and time info to the file name. How can I add the source directory path to the file name? In case anyone is wondering why I... (5 Replies)
Discussion started by: dexter126
5 Replies

5. Shell Programming and Scripting

replace and add characters in filename

I have files named like ABAB09s099E1AAV1.pdf and ABAB09s099E2AAV1.pdf in a directory. I need to add _Lop in the end of the name, like ABAB09s099E1AAV1_Lop.pdf for all files. For files with E2 in the name I also have to replace 99 with 88 in the filename, that would be ABAB09s088E2AAV1_Lop.pdf ... (3 Replies)
Discussion started by: hakkar
3 Replies

6. Shell Programming and Scripting

How to add filename to the end of each line in file

Hi, I'm reading data from comma separated files to DB. Now there is a need to have the name of the input file in each row of that file. How can I do this in unix script? Example: $cat file1 value11,value12, value,13 value21,value22, value,23 value31,value32, value,33 And the result... (2 Replies)
Discussion started by: tmikahan
2 Replies

7. Shell Programming and Scripting

how can i add/modify filename after output?

Hi All, I have a script to convert a file and output the filename with "_output", however it not work. Can help? echo Please input list file name: read listn for file in `cat $listn.txt` do convert $file > $file_output Thanks all!! (3 Replies)
Discussion started by: happyv
3 Replies

8. Shell Programming and Scripting

add timestamp to filename

Does anyone know how to add a timestamp to a file's name extension in a shell script? Please help.. (3 Replies)
Discussion started by: walterja
3 Replies

9. UNIX for Dummies Questions & Answers

Add date to a filename

Hi I want to add the date to a filename in a script I have. So I want exp myfile01-FEB-2005.dmp How do I get the 01-FEB-2005 in there? Cheers Rich (3 Replies)
Discussion started by: richard1975
3 Replies

10. UNIX for Dummies Questions & Answers

how to add a timestamp to a filename?

whats going on guys. below is a script i made and am just curious if there is a "time stamp" command. so i can set the timestamp in a filename. #! /bin/ksh # # This scripts takes a list of files in the INDIR variable and compairs it to a list of files that are open in the same directory.... (2 Replies)
Discussion started by: Optimus_P
2 Replies
Login or Register to Ask a Question