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...
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
#!/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.
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)
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)
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)
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)
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)
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)
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)