Incrementing with a twist - please help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Incrementing with a twist - please help
# 8  
Old 03-04-2010
rdcwayx:

You're very welcome. Regarding the bits, don't worry about it. It's the thought that counts Smilie

Alister
# 9  
Old 03-04-2010
devtakh
perl does it automagically:
Code:
#!/usr/bin/perl

$x = "ab8";
foreach (1..10) {

   print $x++, "\n";

}

$ ./1.pl
ab8
ab9
ac0
ac1
ac2
ac3
ac4
ac5
ac6
ac7


Code:

# 10  
Old 03-04-2010
Quote:
Originally Posted by bigearsbilly
ab8
ab9
ac0
ac1
That sequence fragment is incorrect. Ignoring case sensitivity, it should be:
Code:
ab8
ab9
aba
abb
...snip...
aby
abz
ac0
ac1

Alister
# 11  
Old 03-04-2010
Question

I appreciate all the help and explanation Alister. It is a very clever method of incrementing. Also thanks for the perl examples. Unfortunately I am going to run this script on some older machines and want to use ksh or csh.

Now I'm trying to figure out how to take this constantly increasing number and assign it to a file name when files are put into the directory. So say the last file was renamed to:
7BC.txt
I then copy it somewhere else.

then 10 minutes later another file was dropped in the directory and the script would rename it:
7BD.txt
then copy it.

Right now I have the last incrementing number stored off to a file so I can grab it, but I'm having trouble incrementing it based on what code I've gotten from you guys. I can do this with regular numbers, but not with letters. Please help if you can.

Thanks!
# 12  
Old 03-05-2010
You can do something like this.

Redirect the output of the command to a file "sequences":

Code:
000
001
002
.
.
ZZZ

Create a file "ref" with the next line number:

Code:
echo "1" > ref

Now you can move the files with this script:

Code:
#/bin/sh

num=$(< ref)	# read the linenumber from the file ref
newname=$(awk -v var=$num 'NR==var{print $0 ".txt";exit}' sequences)	# new filename

mv file newname

num=$(( $num + 1 ))	# increase line number
echo $num > ref		# store new number in ref

Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File Listing, with a Twist?

Greetings! I have a quick question which must be deferred to those with greater skill than myself :) In this situation, I wish to create a list of all the files on an entire partition in descending order sorted by date. I tried numerous switches for ls, and found this line to be the closest... (4 Replies)
Discussion started by: LinQ
4 Replies

2. Shell Programming and Scripting

Simple two file compare with twist

I have file1 and file2 I lookup field3 from file2 in field1 of file1 and if there is a match, output field 2,3,5 from file2. I now want to add field2 of file1 in the output. I suspect what I have to do is read the entire line of file1 into a 2 dim array? pls help. (1 Reply)
Discussion started by: tmonk1
1 Replies

3. Shell Programming and Scripting

Section Removal With sed; and With a Twist . . .

Hello folks! Raised a bump on my head trying to figure this one out ;) I have an xml file which needs to be edited, removing an entire property section in the work. Here's what the target section layout looks like: <property name="something"> {any number of lines go here} </property>... (7 Replies)
Discussion started by: LinQ
7 Replies

4. Shell Programming and Scripting

Simple two file compare with twist

I have file1 and file2 I lookup field3 from file2 in field1 of file1 and if there is a match, output field 2,3,5 from file2. I now want to add field2 of file1 in the output. I suspect what I have to do is read the entire line of file1 into a 2 dim array? pls help. here is my code: ... (9 Replies)
Discussion started by: jack.bauer
9 Replies

5. Shell Programming and Scripting

Delete duplicate lines... with a twist!

Hi, I'm sorry I'm no coder so I came here, counting on your free time and good will to beg for spoonfeeding some good code. I'll try to be quick and concise! Got file with 50k lines like this: "Heh, heh. Those darn ninjas. They're _____."*wacky The "canebrake", "timber" & "pygmy" are types... (7 Replies)
Discussion started by: shadowww
7 Replies

6. Shell Programming and Scripting

How to merge two files with a slight twist

Hi, a brief introduction on the soundex python module(english sound comparison): import soundex.py a = "neu yorkk" b = "new york city" print soundex.sound_similar(a, b) output: 1 Suppose I want to merge two files, called mergeleft.csv and mergeright.csv Mergeleft.csv: ... (0 Replies)
Discussion started by: grossgermany
0 Replies

7. UNIX for Dummies Questions & Answers

file count with a twist

Hello Everyone, I am using the korn shell. I was hoping to find a set of commands to count files in a directory. I am using: ls /home/name/abc* | wc -l This command works fine when a file matches abc* (returns only the file count) , however when no file(s) are found I get... (2 Replies)
Discussion started by: robert4732
2 Replies

8. UNIX for Advanced & Expert Users

building a kernel (with a twist)

Hey all, I am working on a static analysis tool and I wan't to see if it can find bugs in the linux kernel, it uses LLVM framework to analyse the instructions. Long story short I need to build the kernel with a custom compiler. The compiler will create byte code files where binaries usually... (2 Replies)
Discussion started by: zigga15
2 Replies

9. Shell Programming and Scripting

Compare 2 files yet again but with a twist

Ok so I have a file which contains 2 columns/fields and I have another file with 2 columns. The files look like: file1: 1 33 5 345 18 2 45 1 78 31 file2: 1 c1d2t0 2 c1d3t0 3 c1d4t0 4 c1d4t0 5 c2d1t0 6 c2d1t0 7 c2d1t0 8 c2d1t0 9 c2d1t0 10 c2d1t0 (11 Replies)
Discussion started by: Autumn Tree
11 Replies

10. UNIX for Dummies Questions & Answers

how do I log into this machine - with a twist...

I know this topic has been covered in one form or another, but it hasn't been covered to handle my problem. I was given a Sparc4 running Solaris 2.5.1 The root password is unknown. This machine has no cdrom drive and it has no floppy drive. I tried booting into the single user mode, but... (1 Reply)
Discussion started by: xyyz
1 Replies
Login or Register to Ask a Question