Sponsored Content
Top Forums Shell Programming and Scripting Making 256 files with variables Post 302404667 by mario8eren on Thursday 18th of March 2010 05:41:23 AM
Old 03-18-2010
Quote:
Originally Posted by alister
Hello, mario8eren:

If the file with the letters to be substituted is called "template", the following script will create 256 files in the current directory. The name of each file indicates the values that were substituted for each letter:

Code:
#!/bin/sh

template=$1
for values in {60,150,240,330}\ {60,150,240,330}\ {60,150,240,330}\ {60,150,240,330}; do
    set $values
    X=$1; Y=$2; Z=$3; M=$4
    sed "s/X\$/$X/;s/Y\$/$Y/;s/Z\$/$Z/;s/M\$/$M/" "$template" > "X$X-Y$Y-Z$Z-M$M"
done

Regards,
Alister
Thank you very much it helped me a lot Alister Smilie . Also thanks to others for giving good ideas.

Mario

---------- Post updated at 07:16 AM ---------- Previous update was at 02:02 AM ----------

Hey guys, I ran into another problem today, if I add some lines to the script it works, but if I add another part it gives me an line syntax error. I coloured the non-working part red:

Code:
#!/bin/sh

template=$1
for values in {60,150,240,330}\ {60,150,240,330}\ {60,150,240,330}\ {60,150,240,330}; do
    set $values
    X=$1; Y=$2; Z=$3; M=$4
    mkdir "X$X-Y$Y-Z$Z-M$M"
    cp script ./"X$X-Y$Y-Z$Z-M$M"
    sed "s/X\$/$X/;s/Y\$/$Y/;s/Z\$/$Z/;s/M\$/$M/" "$template" > ./X$X-Y$Y-Z$Z-M$M/"X$X-Y$Y-Z$Z-M$M"
    cd ./X$X-Y$Y-Z$Z-M$M
    babel -igzmat "X$X-Y$Y-Z$Z-M$M" -oxyz coord.xyz
    source $USELIB/tm510
    x2t coord.xyz > coord
    define <<EOF


    a coord
    ired
    *
    *
    eht



    scf
    iter
    300

    dft
    on

    ri
    on

    *
    EOF

    qsub script
    cd ..
done

Thank you again in advance,

Mario

---------- Post updated 03-18-10 at 04:41 AM ---------- Previous update was 03-17-10 at 07:16 AM ----------

Little update, I added the "define part" of the file into another sh script and used sh command in the first script, so everything is working now as I wanted it.

Thank you all again Smilie .

Mario
 

9 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

pls hlp: making .sh files executable

I've got a file named jdictd.sh containing the following: --- begin file contents --- #! /bin/csh echo I\'m running! java -cp jdictd.jar org.dict.server.JDictd data/dict.ini # Use the following line instead if JRE 1.1 is used # jre -cp jdictd.jar org.dict.server.JDictd data/dict.ini ---end... (2 Replies)
Discussion started by: ropers
2 Replies

2. UNIX for Dummies Questions & Answers

Making files readonly with vi?

Hi, I'm new at this whole Unix thing, but definately learning (lots of fun)... and I was wondering - how do you make a file read-only with vi? I don't mean how do you load up vi in read-only mode, but how do you save a file (or flag a file, or whatever) in vi to read-only? How do you make it... (2 Replies)
Discussion started by: Flyguy
2 Replies

3. Shell Programming and Scripting

Making file with values from different files

Hello, I am stuck up in middle of a script.Pls have a look at the problem and help me in any way out for the same. There are n number of files with n number of contents in a column. for example : file1 has contents in quotes "abcd" "1234-asbcd" "12312"..... file2 has contents in... (4 Replies)
Discussion started by: er_aparna
4 Replies

4. Shell Programming and Scripting

[problem] making a backup files

Hi guys, I'm a little stuck on this problem, I've tried googling it and some trial and error but can't seem to get it working. Basically I need the script to: 1) create a directory called "mybackups", if it doesn't exist 2) go through all the .sh files in the current directory, and copy... (4 Replies)
Discussion started by: chazij
4 Replies

5. Shell Programming and Scripting

Making Variables

Dear Friends, Here I need your help once again. I have a flat file with pipe de-limited format e.g. 12345|1234567890|0|0|0| (Total 5 values) I want to take all non 0 ("Zero") values in variables named as anu1, anu2, anu3, anu4 and anu5. Is it possible? Please guide me. Thank you in... (3 Replies)
Discussion started by: anushree.a
3 Replies

6. Shell Programming and Scripting

[PHP] Need help with making variables Global

I have made a script that requires another php script for functions. I need a way so that the required script can read and write the main script's variables. Best Regards, John Wei ---------- Post updated at 08:54 AM ---------- Previous update was at 08:40 AM ---------- Sorry Guys, EDIT: my... (1 Reply)
Discussion started by: johntzwei
1 Replies

7. UNIX for Advanced & Expert Users

Move files while making a tar

I have the following folder structure code/f1/ code/lib/t1 code/lib/t2 code/lib/t3 code/lib/t3 code/lib_1/t1 code/exc I would like to create a tar with a folder structure below and I can use the following tar command f1 lib/t1 lib/t2 lib/t3 tar -cvf code.tar -C code f1 lib... (4 Replies)
Discussion started by: alpboys
4 Replies

8. Shell Programming and Scripting

Making a script to copy files not seen before (using md5sum)

Hello, I would like to make a script that searches through a SRC folder and copies only files it's never seen before to a DEST folder. SRC = /user/.phonesync/photos-backup DST = /usr/.phonesync/photos-new So basically, I'd start with a: md5sum /user/.phonesync/photos-backup/* >... (29 Replies)
Discussion started by: nbsparks
29 Replies

9. Shell Programming and Scripting

Need script for making files based on some conditions.

Hi All, I have a text file (code_data.txt) with the followig data. AMAR AB123456 XYZ KIRAN CB789 ABC RAJ CS78890 XYZ KAMESH A33535335 ABC KUMAR MD678894 MAT RITESH SR3535355... (26 Replies)
Discussion started by: ROCK_PLSQL
26 Replies
All times are GMT -4. The time now is 04:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy