Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...keep up the good work with this forum, I think this is the best one around. ...you actually try to help people learn for themselves. ...I commend you on providing a very good, open learning atmosphere, where usually egos are left behind..."

Geography

Where in the world do Tek-Tips members come from?

Tool that'll create separate scripts from a file.

birdboyee (IS/IT--Management)
16 Jun 12 14:26
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
PHV (MIS)
16 Jun 12 17:48
I'd use awk:

CODE --> typed,untested

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: How Do I Get Great Answers To my Tek-Tips Questions?
FAQ181-2886: How can I maximize my chances of getting an answer?

birdboyee (IS/IT--Management)
16 Jun 12 21:37
works great, thanks!
birdboyee (IS/IT--Management)
18 Jun 12 1:05
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?
birdboyee (IS/IT--Management)
18 Jun 12 1:13
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!

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close