How to extract a record in a text on string match in a file using bash
- by private
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.