Little Help on This script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Little Help on This script
# 8  
Old 04-28-2012
the output has to be
Code:
copy table_name from path abc.uml on node1,
abd.uml on node2,
xxx.uml on node3,
yyy.uml on node1
ccc.uml on node2 delimiter '|';

there was a comma missing sorry.........

the original progression has to be 150 files every time

The progression on node1,node2,node3 has to repetitive with on end of every filename.
Moderator's Comments:
Mod Comment Please click this link: How to use [code][/code] tags

---------- Post updated 04-28-12 at 04:09 PM ---------- Previous update was 04-27-12 at 10:06 PM ----------

Please help me with this friends.

Last edited by Scrutinizer; 04-28-2012 at 07:49 AM..
# 9  
Old 04-30-2012
All Shell method (using a disc workfile).
Adjust $max for the number of tables per copy statement. Assumes that your list of tables contains an exact multiple of $max lines.
Note that the script does not contain any "for x in ..." statements because the example in post #1 is liable to break with 100,000 arguments!

Code:
input=files.txt
output=output.txt
>output.txt
workfile=workfile.$$
touch "${workfile}"
max=5   # Tables per copy statement

counter=0
node=0
cat ${input} |while read line
do
        #
        node=$((${node} + 1))
        if [ $node -gt 3 ]
        then
                node=1
        fi
        #
        counter=$((${counter} + 1))
        if [ ${counter} -gt $max ]
        then
                if [ -s "${workfile}" ]
                then
                        cat ${workfile} >> ${output}
                        > ${workfile}
                fi
                counter=1
        fi
        if [ $counter -eq 1 ]
        then
                echo "copy table_name from path $line on node${node}," >>${workfile}
                continue
        fi
        if [ $counter -eq $max ]
        then
                echo "                                           $line on node${node} delimiter '|';" >> ${workfile}
                continue
        fi
                echo "                                           $line on node${node}," >> ${workfile}
done

if [ -s "${workfile}" ]
then
        cat ${workfile} >> ${output}
fi
rm ${workfile}



./scriptname
copy table_name from path abc.uml on node1,
                                           abd.uml on node2,
                                           xxx.uml on node3,
                                           yyy.uml on node1,
                                           ccc.uml on node2 delimiter '|';
copy table_name from path fff.uml on node3,
                                           ggg.uml on node1,
                                           eee.uml on node2,
                                           lll.uml on node3,
                                           kkk.uml on node1 delimiter '|';
copy table_name from path dbd.uml on node2,
                                           ltm.uml on node3,
                                           opo.uml on node1,
                                           ikj.uml on node2,
                                           plp.uml on node3 delimiter '|';


Last edited by methyl; 04-30-2012 at 10:44 AM.. Reason: paste issues
Login or Register to Ask a Question

Previous Thread | Next Thread

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to block first bash script until second bash script script launches web server/site?

I'm new to utilities like socat and netcat and I'm not clear if they will do what I need. I have a "compileDeployStartWebServer.sh" script and a "StartBrowser.sh" script that are started by emacs/elisp at the same time in two different processes. I'm using Cygwin bash on Windows 10. My... (3 Replies)
Discussion started by: siegfried
3 Replies

2. Shell Programming and Scripting

Shell script works fine as a standalone script but not as part of a bigger script

Hello all, I am facing a weird issue while executing a code below - #!/bin/bash cd /wload/baot/home/baotasa0/sandboxes_finance/ext_ukba_bde/pset sh UKBA_publish.sh UKBA 28082015 3 if then echo "Param file conversion for all the areas are completed, please check in your home directory"... (2 Replies)
Discussion started by: ektubbe
2 Replies

3. UNIX for Dummies Questions & Answers

Calling a script from master script to get value from called script

I am trying to call a script(callingscript.sh) from a master script(masterscript.sh) to get string type value from calling script to master script. I have used scripts mentioned below. #masterscript.sh ./callingscript.sh echo $fileExist #callingscript.sh echo "The script is called"... (2 Replies)
Discussion started by: Raj Roy
2 Replies

4. Shell Programming and Scripting

Script will keep checking running status of another script and also restart called script at night

I am using blow script :-- #!/bin/bash FIND=$(ps -elf | grep "snmp_trap.sh" | grep -v grep) #check snmp_trap.sh is running or not if then # echo "process found" exit 0; else echo "process not found" exec /home/Ketan_r /snmp_trap.sh 2>&1 & disown -h ... (1 Reply)
Discussion started by: ketanraut
1 Replies

5. 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
Login or Register to Ask a Question