Renumbering files scripting help!


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Renumbering files scripting help!
# 1  
Old 04-22-2008
Renumbering files scripting help!

I am new to the world of UNIX scripting - and would like to make the following script:

I have 100 files numbered 1-100. However - i would like to continue the file list - so that I add another 100 files following on, so that file 101 = 99; file 102 = 98 ; 103 = 97 and so on....
(basically ... original_file_number + new_file_number = 200)

I imagine this to be a very simple task, can anyone help?

Many thanks in advance,

AJC1985
# 2  
Old 04-22-2008
With bash and ksh :
Code:
new=101
while (( new<200 ))
do
   (( old = 200 - new ))
   cp $old $new
   (( new += 1 ))
done

With bash or ksh93
Code:
for (( new=101; new<200; new++ ))
do
   (( old = 200 - new ))
   cp $old $new
done

Result:
Code:
cp 99 101
cp 98 102
cp 97 103
cp 96 104
cp 95 105
. . .
cp 5 195
cp 4 196
cp 3 197
cp 2 198
cp 1 199

Jean-Pierre.
# 3  
Old 04-22-2008
Many thanks Jean-Pierre,

Works a treat.

Andrew

P.S. I imagine I will start contributing to this forum much more as I dive into this PhD...
# 4  
Old 04-22-2008
okay - slightly complexing the situation...

what if my files are names for example abc1 - abc100 (so new files should be names abc101-abc200 .
Also... does the files being say .png files complex the situation?

Cheers for your further assistance.

Andrew
# 5  
Old 04-22-2008
If these are static things then modifying the script to just add those where necessary is trivial. If they need to be dynamic (today abc, tomorrow toyota, next Wednesday fudge and Smarties) then perhaps you can elaborate on what might change and what the range of possible changes might be.

Code:
for (( new=101; new<200; new++ ))
do
   (( old = 200 - new ))
   cp abc$old.png abc$new.png
done

For one possible generalization, you could devise a script which accepts a base number, a new number, a prefix and a suffix.

Code:
#!/bin/bash

case $# in 4);; *) echo "Syntax: $0 base new prefix suffix" >&2; exit 2;; esac

base=$1
top=$2
prefix=$3
suffix=$4

for (( new=$base; new<$top; new++ ))
do
   (( old = $top - new ))
   cp $prefix$old$suffix $prefix$new$suffix
done


Last edited by era; 04-22-2008 at 06:44 PM.. Reason: Generalized script
# 6  
Old 04-22-2008
new=101
while (( new<200 ))
do
(( old = 200 - new ))
cp abc$old abc$new
(( new += 1 ))
done
# 7  
Old 04-22-2008
Cheers guys - that is exactly what I needed.
Thanks for your time and help.

Andrew
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count Repetitive Number in a column and renumbering using awk

Unable to get the desired output. Need only the rows which has repeated values in column 5. Input File <tab separated file> chr1 3773797 3773797 CEP10 1 chr1 3773797 3773797 CEP104 2 chr1 3689350 3689350 SMIM1 2 chr1 3773797 3773797 CEP4 3 chr1 3773797 3773797 EP104 ... (7 Replies)
Discussion started by: himanshu
7 Replies

2. Shell Programming and Scripting

Renumbering files bash script

I am new to the world of Linux scripting, and would like to make the following 2 scripts: I have 67 files named Alk-0001.txt to Alk-0067.txt I would like them to be numbered Alk-002.txt to Alk-0134.txt eg Alk-0001.txt > Alk-0002.txt Alk-0002.txt > Alk-0004.txt Alk-0003.txt > Alk-0006.txt ... (3 Replies)
Discussion started by: tollyboy_uk
3 Replies

3. Shell Programming and Scripting

Renumbering of COBOL Source code

Hi, I have written awk script to replicate RENUM function of ISPF. Please anyone has simple script than that. awk '{i=i+10;line=substr($0,7,73); printf("%06d%s\n", i, line) }' ABC.cob where ABC.cob is Cobol source code. (4 Replies)
Discussion started by: kailas.girase
4 Replies

4. Shell Programming and Scripting

renumbering within a file

Hi All, I have 100 files named - rep-0.txt, rep-2.txt...rep-99.txt. They each contain information in the following format: abc 1 qwe asd 2 zxc poi 3 lkj pdh 4 ldf hgf 5 tyu i would like to re-number , so that all the new files (rep0.dat, rep1,dat....) have... (1 Reply)
Discussion started by: chen.xiao.po
1 Replies

5. Programming

Scripting using flat files

I need some help to create a script that can do the following: I have two flat files with one column that should link the two files' information into one record: 1st Flat File - 3 columns, multiple rows: orderid, Jobnumber, Ordernumber 2nd Flat File - 2 columns, multiple rows: ... (4 Replies)
Discussion started by: Lavelle
4 Replies

6. UNIX for Dummies Questions & Answers

shell scripting with files- how to?

Hi, I'm trying to create a shell script that shows a report of each real user of the system showing for each user the list of files that is in $home and its subdirectories (sorted by hour of modification), clasified by file type, and finally showing the total size and number of files in that... (1 Reply)
Discussion started by: ubu-user
1 Replies

7. UNIX for Dummies Questions & Answers

renaming (renumbering) fasta files

I have a fasta file that looks like this: >Noname ACCAAAATAATTCATGATATACTCAGATCCATCTGAGGGTTTCACCACTTGTAGAGCTAT CAGAAGAATGTCAATCAACTGTCCGAGAAAAAAGAATCCCAGG >Noname ACTATAAACCCTATTTCTCTTTCTAAAAATTGAAATATTAAAGAAACTAGCACTAGCCTG ACCTTTAGCCAGACTTCTCACTCTTAATGCTGCGGACAAACAGA ... I want to... (2 Replies)
Discussion started by: Oyster
2 Replies

8. Shell Programming and Scripting

files Scripting Issue

Hai Guys, I am new to Shell Scripting, I am having a requirement.Please help me.. How to write a KornShell script to find and display all the files that were created before 90 - 120 days from the current date. Regards, Mahesh.. (1 Reply)
Discussion started by: mraghunandanan
1 Replies

9. Shell Programming and Scripting

column renumbering

Hi, I am a beginner in awk scripting! I need your help; I want to replace the fifth column number (which is 15 here) here in this file for example : ATOM 142 N PRO A 15 ATOM 143 CD PRO A 15 ATOM 144 HD1 PRO A 15 ATOM ... (5 Replies)
Discussion started by: adak
5 Replies

10. UNIX for Dummies Questions & Answers

renumbering user id

Other than deleting and recreating a user can a users id number be changed? I need to have my user id the same on more than one system. (1 Reply)
Discussion started by: thumper
1 Replies
Login or Register to Ask a Question