Duplicating and changing sh file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Duplicating and changing sh file
# 1  
Old 10-04-2012
Duplicating and changing sh file

Hello,
I have a file named file_1.sh that I want to duplicate into file_2.sh, file_3.sh,..., etc.
I also need to change the text within each file so that it would fit the file name. For example, in file_1.sh there is a command to save some output as 'output_1.txt', and also there is an input range of 1-100. Therefore, file_2.sh should have 'output_2.txt' and a range of 2-101.
Please help.
Thanks a lot.
# 2  
Old 10-04-2012
I doubt you need 100 different scripts. You can probably use the same one over and over by modifying it slightly.

something.sh:
Code:
#!/bin/sh

echo "Range of $1 to $2"

The loop:

Code:
for X in `seq 1 100`
do
        ./something.sh $X 101 > file_${X}.txt
done

# 3  
Old 10-04-2012
I think I actually do need to have multiple scripts. Perhaps I didn't explain myself well enough - the input range is actually a batch of image files named image_1.tif, image_2.tif,...,etc. Each script is used to call for some program that analyzes these images, and each time I want to analyze 100 images with a sliding window of 1 (i.e., images 1-100, 2-101,...).
I am using: $(ls image_* | sed -n 1,100p) to select the images, and I want the output of these program to be saved according to the name of the first image in each set (for instance, images 1-100 should produce an output named output1.txt).
Thanks.
# 4  
Old 10-04-2012
And that needs 100 shell scripts why?

Another problem, though -- your images aren't going to sort right. You should have them named image_0001, not image_1, and so forth.

Code:
#!/bin/bash

WINDOW=5

set -- image_*

BATCH=1

while [ "$#" -gt 0 ]
do
        LISTFILES=""
        N=1
        while [ $N -le $WINDOW ]
        do
                LISTFILES="$LISTFILES ${1}"
                shift
                let N=N+1
        done

        echo "Batch $BATCH is $LISTFILES"
        let BATCH=BATCH+1

        set -- $LISTFILES "$@"
        shift
done

Code:
$ ./listfiles.sh

Batch 1 is  image_0001.tif image_0002.tif image_0003.tif image_0004.tif image_0005.tif
Batch 2 is  image_0002.tif image_0003.tif image_0004.tif image_0005.tif image_0006.tif
Batch 3 is  image_0003.tif image_0004.tif image_0005.tif image_0006.tif image_0007.tif
Batch 4 is  image_0004.tif image_0005.tif image_0006.tif image_0007.tif image_0008.tif
Batch 5 is  image_0005.tif image_0006.tif image_0007.tif image_0008.tif image_0009.tif
Batch 6 is  image_0006.tif image_0007.tif image_0008.tif image_0009.tif image_0010.tif
Batch 7 is  image_0007.tif image_0008.tif image_0009.tif image_0010.tif image_0011.tif
Batch 8 is  image_0008.tif image_0009.tif image_0010.tif image_0011.tif image_0012.tif
Batch 9 is  image_0009.tif image_0010.tif image_0011.tif image_0012.tif image_0013.tif
Batch 10 is  image_0010.tif image_0011.tif image_0012.tif image_0013.tif image_0014.tif
Batch 11 is  image_0011.tif image_0012.tif image_0013.tif image_0014.tif image_0015.tif
Batch 12 is  image_0012.tif image_0013.tif image_0014.tif image_0015.tif image_0016.tif
Batch 13 is  image_0013.tif image_0014.tif image_0015.tif image_0016.tif image_0017.tif
Batch 14 is  image_0014.tif image_0015.tif image_0016.tif image_0017.tif image_0018.tif
Batch 15 is  image_0015.tif image_0016.tif image_0017.tif image_0018.tif image_0019.tif
Batch 16 is  image_0016.tif image_0017.tif image_0018.tif image_0019.tif image_0020.tif
Batch 17 is  image_0017.tif image_0018.tif image_0019.tif image_0020.tif image_0021.tif
Batch 18 is  image_0018.tif image_0019.tif image_0020.tif image_0021.tif image_0022.tif
Batch 19 is  image_0019.tif image_0020.tif image_0021.tif image_0022.tif image_0023.tif
Batch 20 is  image_0020.tif image_0021.tif image_0022.tif image_0023.tif image_0024.tif
Batch 21 is  image_0021.tif image_0022.tif image_0023.tif image_0024.tif image_0025.tif
Batch 22 is  image_0022.tif image_0023.tif image_0024.tif image_0025.tif image_0026.tif
Batch 23 is  image_0023.tif image_0024.tif image_0025.tif image_0026.tif image_0027.tif
Batch 24 is  image_0024.tif image_0025.tif image_0026.tif image_0027.tif image_0028.tif
Batch 25 is  image_0025.tif image_0026.tif image_0027.tif image_0028.tif image_0029.tif
Batch 26 is  image_0026.tif image_0027.tif image_0028.tif image_0029.tif image_0030.tif
Batch 27 is  image_0027.tif image_0028.tif image_0029.tif image_0030.tif image_0031.tif
Batch 28 is  image_0028.tif image_0029.tif image_0030.tif image_0031.tif image_0032.tif
Batch 29 is  image_0029.tif image_0030.tif image_0031.tif image_0032.tif image_0033.tif
Batch 30 is  image_0030.tif image_0031.tif image_0032.tif image_0033.tif image_0034.tif
Batch 31 is  image_0031.tif image_0032.tif image_0033.tif image_0034.tif image_0035.tif
Batch 32 is  image_0032.tif image_0033.tif image_0034.tif image_0035.tif image_0036.tif
Batch 33 is  image_0033.tif image_0034.tif image_0035.tif image_0036.tif image_0037.tif
Batch 34 is  image_0034.tif image_0035.tif image_0036.tif image_0037.tif image_0038.tif
Batch 35 is  image_0035.tif image_0036.tif image_0037.tif image_0038.tif image_0039.tif
Batch 36 is  image_0036.tif image_0037.tif image_0038.tif image_0039.tif image_0040.tif
Batch 37 is  image_0037.tif image_0038.tif image_0039.tif image_0040.tif image_0041.tif
Batch 38 is  image_0038.tif image_0039.tif image_0040.tif image_0041.tif image_0042.tif
Batch 39 is  image_0039.tif image_0040.tif image_0041.tif image_0042.tif image_0043.tif
Batch 40 is  image_0040.tif image_0041.tif image_0042.tif image_0043.tif image_0044.tif
Batch 41 is  image_0041.tif image_0042.tif image_0043.tif image_0044.tif image_0045.tif
Batch 42 is  image_0042.tif image_0043.tif image_0044.tif image_0045.tif image_0046.tif
Batch 43 is  image_0043.tif image_0044.tif image_0045.tif image_0046.tif image_0047.tif
Batch 44 is  image_0044.tif image_0045.tif image_0046.tif image_0047.tif image_0048.tif
Batch 45 is  image_0045.tif image_0046.tif image_0047.tif image_0048.tif image_0049.tif
Batch 46 is  image_0046.tif image_0047.tif image_0048.tif image_0049.tif image_0050.tif
Batch 47 is  image_0047.tif image_0048.tif image_0049.tif image_0050.tif
Batch 48 is  image_0048.tif image_0049.tif image_0050.tif
Batch 49 is  image_0049.tif image_0050.tif
Batch 50 is  image_0050.tif

$

Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

duplicating a line

I have a text file which is the results of running a tests hundreds of times. For simplicity let's say that each test consists of 5 lines of text numbered 1-5 e.g. 1 aaa aaa aaa 2 bbb bbb bbb 3 ccc ccc ccc 4 ddd ddd ddd 5 eee eee eee 1 aaa aaa aaa 2 bbb bbb bbb 3 ccc... (4 Replies)
Discussion started by: millsy5
4 Replies

2. Shell Programming and Scripting

mv duplicating directories

Hi Folks, I've put together a script for sorting my backup files into sub folders to be run from a cron job. Each file is named username.tar.gz and the file /etc/trueuserowners contains all users and their owner in the format "user: owner". The script works fine identifying users and their owners... (10 Replies)
Discussion started by: beddo
10 Replies

3. UNIX for Dummies Questions & Answers

Duplicating MAC linux or net?

hi guys I have a IBM eServer BladeCenter HS12 with Linux Red Hat 5.4 installed on it, it is using Bonding. ifcfg-bond0 DEVICE=bond0 BOOTPROTO=none ONBOOT=yes TYPE=Ethernet IPADDR=x.x.x.x NETMASK=x.x.x.x GATEWAY=x.x.x.x USERCTL=no IPV6INIT=no PEERDNS=no BONDING_OPTS="miimon=80... (1 Reply)
Discussion started by: karlochacon
1 Replies

4. Red Hat

Duplicating ethernet speed

Hi guys, Suppose you have a server with two ethernet cards (1GB each) and each cards are connecting to two different switches cisco 3750. My question is: How can I setup my server's network interfaces to increase the throughput up to 2GB? is it possible? If not, do you know another way to up... (3 Replies)
Discussion started by: iga3725
3 Replies

5. UNIX for Dummies Questions & Answers

remove duplicating lines

Hi, i have a webserver logfile and want to count how many page views there have been. I was thinking about removing lines that begin with the same user and same date&time, because it indicates they were just looking at one page and multiple hits were counted. My question is how do I do this?... (6 Replies)
Discussion started by: JudithBorg
6 Replies

6. HP-UX

duplicating ignite tapes

I have a B180L controller running HP-UX 10.2 with an internal DDS2 tape drive and an external Surestore DDS (24gb) tape drive. I want to make duplicate copies of ignite tapes from one tape drive to another. What is the best way to do this? (1 Reply)
Discussion started by: garyb
1 Replies

7. Post Here to Contact Site Administrators and Moderators

Sorry for duplicating posts

SORRY FOR DUPLICATING POSTS, COULD U JUST REMOVE THE FIRST ONE. Thank u. (1 Reply)
Discussion started by: vrguha
1 Replies

8. Shell Programming and Scripting

duplicating 1st row of data

Hi, I have data in the following format: data1 data2 data3 data4 data5 data6 data7 data8 data9 data10 I require the final output to be: data1 data1 data1 data1 i only require the 1st line but I need to replicate it in n rows where n is the number of rows where data... (4 Replies)
Discussion started by: ReV
4 Replies
Login or Register to Ask a Question