To Create shell script files from a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting To Create shell script files from a shell script
# 1  
Old 07-27-2010
To Create shell script files from a shell script

Dear Unix and Linux users,
Good evening to all.
I'm new to this community and thank you for having an wonderful forum.

Dear members i had to create almost some 300 shell script files for a particular task.
I tried something like this....

Code:
#!usr/bin/sh
fname=epdb_jobs
for x in `cat $fname`
do
if [ ! -s $x.epdb.com ]
then
echo Creating file...
cat > $x.epdb.com <<EOF
echo fname1=num_$x.txt
for y in `cat $fname1`
do
head -$y t_$x.mol2 | tail -n 200 | head -48 >>rlig_$x.mol2
done
stop
EOF
fi
echo "done $x"
done


By using this script i read the part of the filename from epdb_jobs file and then
i want a new file to be created such that
1RAA.epdb.com
this file should be like the one shown below

Code:
fname1=num_$x.txt
for y in `cat $fname1`
do
head -$y t_$x.mol2 | tail -n 200 | head -48 >>rlig_$x.mol2
done

I have to create 300 different files like this I don't know where i'm going wrong.
please help me.Thanks in advance.
Neha.

Last edited by Scott; 07-27-2010 at 11:18 AM.. Reason: Code tags, please...
# 2  
Old 07-27-2010
Within the here document any Shell special characters must be escaped with a reverse solidus character to stop the current Shell actioning them:

Code:
cat > $x.epdb.com <<EOF
echo fname1=num_\$x.txt
for y in \`cat \$fname1\`
do
head -\$y t_\$x.mol2 | tail -n 200 | head -48 >>rlig_\$x.mol2
done
stop
EOF


Not sure whether the line "stop" should be there?
# 3  
Old 07-27-2010
Here we go:
Code:
#!/usr/bin/sh

IFS="
"

fname=epdb_job

for x in `cat $fname`
do
    if [ ! -s $x.epdb.com ]
    then
        echo Creating file...
        cat > $x.epdb.com <<EOF
echo fname1=num_$x.txt
for y in \`cat \$fname1\`
do
    head -\$y t_\$x.mol2 | tail -n 200 | head -48 >>rlig_\$x.mol2
done
EOF
    fi
    echo "done $x"
done

The problem was that the back-ticks needed escaping as it was trying to run that cat command. I've also escaped the variable inside the back-ticks as otherwise it's not printed.

The IFS="
"
Bit makes sure that the for x in `cat $fname` skips spaces and only acts on new lines, if you use spaces to separate entries then take out the IFS bit.

HTH
Ben
# 4  
Old 07-28-2010
Dear Members,
Thank you for ur help.
It worked so well.
Neha
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to create or convert to pdf files from csv files using shell script?

Hi, Can anyone help me how to convert a .csv file to a .pdf file using shell script Thanks (2 Replies)
Discussion started by: ssk250
2 Replies

2. Shell Programming and Scripting

How to create a shell script to remove the files on solaris server at 00000hrs?

Hi folks, As per mentioned in the title, how to create a shell script to delete those files from the server at 00000hrs every day? Thanks in advance :) (2 Replies)
Discussion started by: kimurayuki
2 Replies

3. Homework & Coursework Questions

shell script that can create, monitor the log files and report the issues for matching pattern

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: Write an automated shell program(s) that can create, monitor the log files and report the issues for matching... (0 Replies)
Discussion started by: itian2010
0 Replies

4. Shell Programming and Scripting

how to create the files dynamically in c shell script

how can i CREATE a txt file dynamically in c shell: for instance: #! /bin/csh for each i (*) cat>file$i.txt for each j do .... (1 Reply)
Discussion started by: jdsignature88
1 Replies

5. UNIX for Dummies Questions & Answers

Create a shell script for write files with 2 parameters

Hello, I'm a newbie in shell script. So, i would like to create a shell script which take 2 IN parameters (PARAM1 and PARAM2). This script need to create 2 files as : I need to create this file /etc/apache2/sites-available/PARAM2 : <VirtualHost *:80> DocumentRoot "/home/PARAM1/www"... (0 Replies)
Discussion started by: chatlumo
0 Replies

6. Shell Programming and Scripting

To write a shell script which groups files with certain pattern, create a tar and zip

Hi Guru's, I have to write a shell script which groups file names based upon the certain matching string pattern, then creates the Tar file for that particular group of files and then zips the Tar file created for the respective group of files. For example, In the given directory these files... (3 Replies)
Discussion started by: rahu_sg
3 Replies

7. Shell Programming and Scripting

Shell Script Create List of Deleted Files

Hi, I want to put all the deleted files in a txt file. Because i want to backup my image server which has thousands of jpg images. I wrote a shell script which will copies images from image server to backup image server. I setup a cronjob which runs on every five minutes. & through timestamp it... (8 Replies)
Discussion started by: mirfan
8 Replies

8. Shell Programming and Scripting

create a shell script that calls another script and and an awk script

Hi guys I have a shell script that executes sql statemets and sends the output to a file.the script takes in parameters executes sql and sends the result to an output file. #!/bin/sh echo " $2 $3 $4 $5 $6 $7 isql -w400 -U$2 -S$5 -P$3 << xxx use $4 go print"**Changes to the table... (0 Replies)
Discussion started by: magikminox
0 Replies

9. Shell Programming and Scripting

How To create Flat Files using Unix Shell Script?

Hi all, How to create Flat Files using Unix Shell Script. The Script is supposed to be sheduled to run at a particular time? Thanks in advance Appu (4 Replies)
Discussion started by: Aparna_k82
4 Replies
Login or Register to Ask a Question