Renaming a file that starts with "-"


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming a file that starts with "-"
# 8  
Old 12-29-2014
Sorry, I meant to answer Scrutinizer first suggestion.
I use Ubuntu Linux (14.04.0x) and I am using bash.
The problem is this:
I am using a script to download files that all have the same name "-.txt" (without the quotes) and I am trying to write a script that once it downloads the first file (-.txt) it will rename it to "1.txt" (again, without quotes) and so the second downloaded file ( also named -.txt) will be renamed 2.txt.
Since these files are large they do take some time to be downloaded (each files is ~ 120 MB)

Thank you all again

---------- Post updated at 05:55 PM ---------- Previous update was at 05:23 PM ----------

OK, problem solved. It was a bug in the downloading python script.
The script was made to download "ALL" files once launched, and therefore, it will download all files (all with name "-.txt") before the loop moves to the second command which is to rename the files.
I am to fix the bug, and then run the script.

How did I figure it out?
Out of frustration, I wrote this script:
Code:
for i in {1..5}
do
touch ./-.txt
mv ./-txt $i.txt
done

The result was, as I expected (and hoped) 1.txt, ..., 5.txt
so I directed my attention to understand how the python script works (I did not go through the script, though) and watched it, trying to figure out why does it pass the mv command?
I then added a couple of sleep 10 commands after the downloading command and the mv command to make sure how does each step run... and this is how I figured it out.

Thank you all again for your help and suggestions....
Happy Holidays
# 9  
Old 12-29-2014
How about sharing that script that downloads all the files?
--> As-is, in code tags, please.

So we could see why it names them like that in the first place.
Because what (of the code) you had posted so far would not work at all.

EDIT:
Ahh nevermind, glad it works now.
Happy holidays Smilie
# 10  
Old 12-29-2014
I would have happily shared the Python script, but it belongs to my work.
# 11  
Old 12-30-2014
Good thing you got the bug resolved. Thanks for reporting back....
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Apache 2.4 directory cannot display "Last modified" "Size" "Description"

Hi 2 all, i have had AIX 7.2 :/# /usr/IBMAHS/bin/apachectl -v Server version: Apache/2.4.12 (Unix) Server built: May 25 2015 04:58:27 :/#:/# /usr/IBMAHS/bin/apachectl -M Loaded Modules: core_module (static) so_module (static) http_module (static) mpm_worker_module (static) ... (3 Replies)
Discussion started by: penchev
3 Replies

2. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

3. Shell Programming and Scripting

SFTP batch not renaming file with "put"

I have a .ksh script that creates an sftp batch file and runs it through sftp. It works except for one thing. If I try to "put" to a different name, it doesn't use the specified remote name...it still "puts" the original local name. I've tried both of these, and neither work...it will always... (4 Replies)
Discussion started by: dbiggied
4 Replies

4. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

5. Shell Programming and Scripting

finding the strings beween 2 characters "/" & "/" in .txt file

Hi all. I have a .txt file that I need to sort it My file is like: 1- 88 chain0 MASTER (FF-TE) FFFF 1962510 /TCK T FD2TQHVTT1 /jtagc/jtag_instreg/updateinstr_reg_1 dff1 (TI,SO) 2- ... (10 Replies)
Discussion started by: Behrouzx77
10 Replies

6. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

7. Shell Programming and Scripting

"sed" to check file size & echo " " to destination file

Hi, I've modified the syslogd source to include a thread that will keep track of a timer(or a timer thread). My intention is to check the file size of /var/log/messages in every one minute & if the size is more than 128KB, do a echo " " > /var/log/messages, so that the file size will be set... (7 Replies)
Discussion started by: jockey007
7 Replies

8. UNIX for Dummies Questions & Answers

Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`"

Hi Friends, Can any of you explain me about the below line of code? mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'` Im not able to understand, what exactly it is doing :confused: Any help would be useful for me. Lokesha (4 Replies)
Discussion started by: Lokesha
4 Replies

9. UNIX for Dummies Questions & Answers

How to cat a file , name starts with "-" ?

I have a question - beginning user, just learning unix. I have a file that name starts with a hypen -, such as a name like : -myfile (yes, I know shold not start files names like this, but this is the question I have to figure out, and its driving me nuts) I know that this hyphen is like... (9 Replies)
Discussion started by: HikerLT
9 Replies
Login or Register to Ask a Question