by Ed Morton <morton@[EMAIL PROTECTED]
>
Feb 11, 2008 at 01:08 PM
On 2/11/2008 12:59 PM, juanpo@[EMAIL PROTECTED]
wrote:
> Hi, I'm trying to parse a file that looks like this to create 2
> different files based on the first 3 characters
>
> FL1ABC
> LG1XYZ
> LG2DBA
> LG3PYZ
> FL1CBA
> LG1QWE
> LG2ZXC
>
> The first file will have all records starting with FL1 like this:
> FL1ABC
> FL1CBA
>
> The second file will need to have the FL1 records appended to each of
> the LG records below it like this:
>
> FL1ABCLG1XYZ
> FL1ABCLG2DBA
> FL1ABCLG3PYZ
> FL1CBALG1QWE
> FL1CBALG2ZXC
>
> Is there a way to easily build this logic using awk?
>
> Thanks in advance for any helps you could provide.
>
> Juan.
This will create a file called "list" of all the FL1* records and print
the rest
to stdout:
awk '/^FL1/{key=$0;print > "list";next}{print key $0}' file
Ed.