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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AWK script over my head. Pls Assist

Status
Not open for further replies.

beaster

Technical User
Aug 20, 2001
225
US
I will try and be as detailed as possible for what I need, this is quite over my head.

I have a file called rehome_input which has data similiar to the below inside which is a csv file seperated by commas:

10,5,10,113
11,16,18,123
13,23,8,2

There may be more or less rows each time I run the script. There will be a dummy file called master_rehome which has the word TG_NUM like rxcdp:mo=rxotg-TG_NUM throughout it.

So what I need is a small script which will read the first line from rehome_input file, grab the first field, and cat the master_rehome file to a new file beaster1, but substitute TG_NUM in the new cat'd file with the first field from the first line of rehome_input.

After the first line, first field, I need to move to the next line, first field in rehome_input and do the same, but the new file beaster should be created in sequence.

So I would end up with three final files: beaster1, beaster2, beaster3 if using the above and they would look like:

beaster1

rxcdp:mo=rxocf-10;
rxmop:mo=rxocf-10;

beaster2

rxcdp:mo=rxocf-11;
rxmop:mo=rxotrx-11;

beaster3

rxcdp:mo=rxocf=13;
rxmop:mo=rxocf-13;



I know this is probably really a big pain, but like I said, it is over my head.

Thanks as always,
Beaster
 
Hi beaster,

Run this awk script against rehome_input.
[tt]
BEGIN {FS=",";fn1="master_rehome"}
{
num = $1
fn2 = "beaster" NR
while ((getline < fn1 ) >0) {
gsub (/TG_NUM/,num)
print > fn2
}
close(fn1)
close(fn2)
}
[/tt]
CaKiwi
 
I named the awk script tg_awk1 and ran it and received the following error msg's. Am I doing something wrong?

beaster> awk -f tg_awk1 rehome_input
awk: syntax error near line 5
awk: illegal statement near line 5
awk: syntax error near line 6
awk: illegal statement near line 6
awk: syntax error near line 10
awk: bailing out near line 10

The script is just like above:

BEGIN {FS=&quot;,&quot;;fn1=&quot;master_rehome&quot;}
{
num = $1
fn2 = &quot;beaster&quot; NR
while ((getline < fn1 ) >0) {
gsub (/TG_NUM/,num)
print > fn2
}
close(fn1)
close(fn2)
}
 
Nevermind, Solaris stinks and I had to use nawk. I should have remembered!

Thanks CaKiwi as always!!!!!!!!!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top