Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Tool that'll create separate scripts from a file.

Status
Not open for further replies.

birdboyee

IS-IT--Management
Jun 16, 2012
4
US
root> uname -r
5.10
root> cat /etc/release
Solaris 10 10/08 s10s_u6wos_07b SPARC
Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
Use is subject to license terms.
Assembled 27 October 2008


Hello Everyone! I have a file called “cells” with 3 set of #'s, roughly 400+ lines. My current tool "movrcs" grabs the “cells” file, and creates one huge “mov_rcs” script which is a problem. I want the tool to grab 20 lines of the "cells" file at a time, and create separate script files for them, not one huge output script. Any assistance is greatly appreciated!!!!

omp root> cat cells
62 33 34
103 44 43
104 44 43
105 44 43
106 44 43
107 44 43
108 44 43
109 44 43
110 44 43
112 44 43


omp root> cat movrcs
while read cell prim alt
do
echo "/omp/bin/TICLI -1 move:rcs $cell,altap $alt" >> mov_rcs
echo "sleep 20" >> mov_rcs
echo "/omp/bin/TICLI -1 move:rcs $cell,priap $prim" >> mov_rcs
echo "sleep 40" >> mov_rcs
done < cells


ompeps root> cat mov_rcs
/omp/bin/TICLI -1 "move:rcs 62,altap" 34
sleep 60
/omp/bin/TICLI -1 "move:rcs 62,priap" 33
sleep 60
/omp/bin/TICLI -1 "move:rcs 103,altap" 43
sleep 60
/omp/bin/TICLI -1 "move:rcs 103,priap" 44
sleep 60
/omp/bin/TICLI -1 "move:rcs 104,altap" 43
sleep 60
/omp/bin/TICLI -1 "move:rcs 104,priap" 44
sleep 60
…..output truncated, current tool creates one big file for all lines found in "cells" file.

As mentioned, I want tool to grab every 20 lines of "cells" file, and create a separate file. Script output sample below only grabbed 1 line from "cells" file to create individual scripts, which is similar to what im looking for:


ompeps root> cat mov_rcs1 <--notice 1 at end of file,
/omp/bin/TICLI -1 "move:rcs 62,altap" 34
sleep 60
/omp/bin/TICLI -1 "move:rcs 62,priap" 33
sleep 60


ompeps root> cat mov_rcs2 <--notice 2 at end of file,
/omp/bin/TICLI -1 "move:rcs 103,altap" 43
sleep 60
/omp/bin/TICLI -1 "move:rcs 103,priap" 44
sleep 60
 
I'd use awk:
Code:
nawk '
BEGIN {i=1;out="mov_rcs1"}
{
 printf "/omp/bin/TICLI -1 move:rcs %d,altap %d\nsleep 20\n",$1,$3 >out
 printf "/omp/bin/TICLI -1 move:rcs %d,priap %d\nsleep 40\n",$1,$2 >out
}
!(NR%20){close(out);out="mov_rcs"(++i)}
' cells

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I noticed the tool is not adding the quotes from beginning of "move, and end of altap/priap", it should look this.

/omp/bin/TICLI -1 "move:rcs 62,altap" 34
sleep 60
/omp/bin/TICLI -1 "move:rcs 62,priap" 33
sleep 60
/omp/bin/TICLI -1 "move:rcs 103,altap" 43
sleep 60
/omp/bin/TICLI -1 "move:rcs 103,priap" 44
sleep 60

How can I add the quotes without breaking the code?
 
I figured it out, I added using the \" lol!! Thanks for your help!!!

nawk '
BEGIN {i=1;out="mov_rcs1"}
{
printf "/omp/bin/TICLI -1 \"move:rcs %d,altap\" %d\nsleep 20\n",$1,$3 >out
printf "/omp/bin/TICLI -1 \"move:rcs %d,priap\" %d\nsleep 40\n",$1,$2 >out
}
!(NR%20){close(out);out="mov_rcs"(++i)}
' cells


This is now fixed!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top