How to extract a record in a text on string match in a file using bash

Posted by private on Ask Ubuntu See other posts from Ask Ubuntu or by private
Published on 2013-06-04T08:51:55Z Indexed on 2013/10/29 4:17 UTC
Read the original article Hit count: 408

Filed under:
|

Hi I have a text file sample.txt as

=====record1
title:javabook
price:$120
author:john
path:d:
=====record2
title:.netbook
author:paul
path:f:
=====record3
author:john
title:phpbook
subject:php
path:f:
price:$150
=====record4
title:phpbook
subject:php
path:f:
price:$150

from this I want to split the data based on author, it should split into 2 files which contains

test1.txt

=====record1
    title:javabook
    price:$120
    author:john
    path:d:
=====record3
    author:john
    title:phpbook
    subject:php
    path:f:
    price:$150

and

test2.txt

=====record2
    title:.netbook
    author:paul
    path:f:

like above I want to classify the main sample.txt file into sub files based on author field dynamically. Please suggest me a way to do it.

© Ask Ubuntu or respective owner

Related posts about Windows

Related posts about bash