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!

Awk and big loops

Status
Not open for further replies.

csripriya1

Programmer
May 13, 2003
35
US
Hi All,
I am new to the awk scripting language. I want to split a large file into multiple small files. I am looking for a pattern in the large file and breaking it into smaller files.
This is how my code looks
{
for(i=1;i<=10;i++)
{
file = "xsaa_"
name = ".sdf"
for (j=1;j<=10; j++)
{
print > (file i name)
getline
while($1 !~ /\$\$\$\$/)
{
print > (file i name)
getline
}
}
print > (file i name)
getline

print (file i name " This file has been printed")
}
exit
}

When I change the size of the loop to 100 or 100 I get incomplete output files. I guess this problem should be simple. But I do not where the bug is. Can anyone please help me with this.

Thanks for your time
 
This is in addition to my earlier post. I copied some of the outputfiles to another directory , while the process was still running and writing other outputfiles. Then I did this " tail -n ". It was incomplete.
After the process was done I did " tail -n " again on the same outputfile. I see that it is complete now. Can anyone pl explain this weird situation.

Thanks
 
Code:
BEGIN { prefix="xsaa_"; suffix=".sdf"; i=1 }

$1 ~ /\$\$\$\$/  { i++ }

{ print  > (prefix i suffix) }
 
man csplit

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top