0

I am having a hardtime trying to learn how to have 2 output files based on the header and if its possible named with info from the header...

Example original file:

AAABBB12042018

 Jon238444kdhsljdjd7

 Math37378338kdjdkske

AAABBB14042018

 Ash81272722mddnd

 Jay81727272msnsms

1st file named based on header: file-12042018

Jon238444kdhsljdjd

Math37378338kdjdkske

2nd file named based on header: file-14042018

Ash81272722mddnd

Jay81727272msnsms

I dont mind keeping the header or not, my issue is how to handle multiple output names based on a string within the header

JNevill
  • 38,700
  • 3
  • 27
  • 52

1 Answers1

0

this should do...

$ awk '/^AAABBB/{sub(/^AAABBB/,"file-"); fn=$0; next} {print > fn}' file

if the line starts with this token, replace it with file prefix and print lines to that file.

karakfa
  • 62,998
  • 7
  • 34
  • 47