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

Hi I have a file with following

Status
Not open for further replies.

visitnag

Programmer
Sep 21, 2006
15
IN
Hi

I have a file with following type rrcrds
Field1 field 2...…...field7
Field1 field 2...…...field7
.
.
.
Code 1111222233

Field1 field 2...…...field7
Field1 field 2...…...field7
.
.
.
Code 111122347

Like after every few records the column total written with a code.

Now I would like to write separate files for each code which contains the respective records of the code. Please help

Thank you
 
something like this
Code:
$0 == "" {
  next
}

{
  lines[n++] = $0
}

$0 ~ /Code/  {
  fname = "visitnag_file"(++k)".txt"
  print(fname)
  for (i = 0; i < n; i++) {
    print lines[i] > fname
  }
  n = 0
}
 
Thank you.... It worked perfectly. I have made some corrections to skip the line which contains the 'code'


/^Code/ {
code = $4
if (code != "") {
file = "print/"code".txt";
for (i = 0; i <= n; i++) {
print records > file;
}
n = 0;
}
code = $4;
next;
}
{
records[++n] = $0;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top