Renaming files from aaaa-zzzz to 0001-9999


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renaming files from aaaa-zzzz to 0001-9999
# 1  
Old 12-19-2011
Renaming files from aaaa-zzzz to 0001-9999

Hi,

I am using split in AIX to split a large file into parts, but in AIX, it names the resulting files something like newaaaa, newaaab, newaaac etc (using a-z for each)

I need to rename these new0001, new0002, new0003 etc.

Is there an easy way to do this?

Cheers, Rob
# 2  
Old 12-19-2011
Check the man page for split - GNU split provides a numeric suffix option, not sure about AIX though.
# 3  
Old 12-19-2011
Quote:
Originally Posted by CarloM
Check the man page for split - GNU split provides a numeric suffix option, not sure about AIX though.
AIX doesn't. The switches in AIX are just:

-a SuffixLength Specifies the number of letters to use in forming the suffix portion of the output name files. The number of letters determines the number of possible output filename combinations. The default is two letters.
-b
Number Splits the file into the number of bytes specified by the Number variable. Adding the k (kilobyte) or m (megabyte) multipliers to the end of the Number value causes the file to be split into Number*1024 or Number*1,048,576 byte pieces, respectively.
-l LineCount Specifies the number of lines in each output file. The default is 1000 lines.
# 4  
Old 12-19-2011
How about this, just remove echo if your happy with what it's going to do:

Code:
for file in new[a-z][a-z][a-z][a-z]
do
   let num=num+1
   new=`printf "new%04d" $num`
   echo mv $file $new
done

# 5  
Old 12-20-2011
Thanks. Works fine.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Renaming multiple files in sftp server in a get files script

Hi, In sftp script to get files, I have to rename all the files which I am picking. Rename command does not work here. Is there any way to do this? I am using #!/bin/ksh For eg: sftp user@host <<EOF cd /path get *.txt rename *.txt *.txt.done ... (7 Replies)
Discussion started by: jhilmil
7 Replies

2. UNIX for Dummies Questions & Answers

Renaming files

Hi all, I'm working in a specific directory and I have file names which I'd like to rename but in a way in which I can specify the new filenames as @ARGV or user input at prompt. Can someone shed some light on this? Cheers :) (7 Replies)
Discussion started by: pawannoel
7 Replies

3. Shell Programming and Scripting

renaming files or adding a name in the beginning of all files in a folder

Hi All I have a folder that contains hundreds of file with a names 3.msa 4.msa 21.msa 6.msa 345.msa 456.msa 98.msa ... ... ... I need rename each of this file by adding "core_" in the begiining of each file such as core_3.msa core_4.msa core_21.msa (4 Replies)
Discussion started by: Lucky Ali
4 Replies

4. UNIX for Dummies Questions & Answers

renaming all files

requirement: There are many files inside a directory and all are named like this "out_1". The file names goes on itearation like out_2, out_3 etc.... Now i want to rename all the file names based on the text inside the file. the text in all the files follow a pattern like it satrts... (4 Replies)
Discussion started by: arunmanas
4 Replies

5. Shell Programming and Scripting

read several inputs and if none input set to 9999

need a script that goes something like this #!/usr/bin/bash echo "input up to TEN values, separated by spaces" read vari1 vari2 vari3 vari4 vari5 vari6 vari7 vari8 vari9 vari10 #set null variables to 9999 (somehow?) #now echo all variables echo $vari1 $vari2 $vari3 $vari4 $vari5 $vari6... (1 Reply)
Discussion started by: ajp7701
1 Replies

6. UNIX for Dummies Questions & Answers

renaming files

I have a list of files named ab_*.csv I would like to remane them all by removing the ab_ and have *.csv I did the following but I am surely missing something. /* wrong script */ for i in `ls -1 ab_*`; do mv ab_$i $i; done Thanks in advance. (1 Reply)
Discussion started by: jxh461
1 Replies

7. UNIX for Dummies Questions & Answers

Add two numbers like 0001+1 and get result as 0002

Hi all, I have to add a number like 0001+1=0002. If i put expr 0001 + 1 it is giving result as 2 but i wanted to get 0002. Please tell me how can i get this. Thanks, Sona. (2 Replies)
Discussion started by: Sona
2 Replies

8. UNIX for Dummies Questions & Answers

renaming files

i have a set of *.lst files. now i want to change the names from "lst" to "dat". how to do it? ex.: -rw-r--r-- 1 rram group 22 Sep 21 13:10 a.lst -rw-r--r-- 1 rram group 22 Sep 21 13:09 b.lst -rw-r--r-- 1 rram group 22 Sep 21 13:10 c.lst... (4 Replies)
Discussion started by: raguramtgr
4 Replies
Login or Register to Ask a Question