Guest_imported
New member
- Jan 1, 1970
- 0
Hi. I am very new to awk, and would like some help on this. I have read the previous threads, and couldn't find the references, and didn't understand any of the solutions. Could someone please tell me how to code awk to split a data file that contains several logical files into several physical files (based on "HREC**" and "TREC**" in the first 6 characters)? The output files need to be dynamically named.
Can this be done all in one awk statement? Should I code an awk program?
Here is what I tried so far:
***********************************************
splitfile.awk
***********************************************
This does not work. If I take away the "
", it displays the entire file, which seems correct. How do I split it??? How do I output each logical file to a separate file?
Thanks for anyone's help. Please try and explain the solution and code to me in clear English. Please do not refer me to another thread. I'm not good enough!
Gloria
Can this be done all in one awk statement? Should I code an awk program?
Here is what I tried so far:
***********************************************
Code:
awk -f splitfile.awk $testfile
splitfile.awk
Code:
BEGIN { num = 0 testoutfile = "testoutfile" }
/'^HREC\*\*'/,/'^TREC\*\*'/
{num +=1
print $0 > $testoutfile$num }
This does not work. If I take away the "
Code:
> $testoutfile$num
Thanks for anyone's help. Please try and explain the solution and code to me in clear English. Please do not refer me to another thread. I'm not good enough!
Gloria