Hi,
I need help in UNIX shell script to handle the following:
I have file called File1.txt which contains data something like below:
LibraryName|BookName|Flag-Indicator|COUNT
LIB1|BOOK1|A|12
LIB1|BOOK1|A|2
LIB2|BOOK2|I|1
LIB2|BOOK1|I|4
LIB1|BOOK2|A|12
LIB1|BOOK1|I|22
LIB1|BOOK2|I|8
LIB1|BOOK1|I|4
LIB1|BOOK2|I|3
LIB1|BOOK2|I|2
LIB2|BOOK1|A|12
LIB2|BOOK1|A|2
LIB2|BOOK1|A|22
LIB2|BOOK2|A|2
LIB2|BOOK2|I|3
LIB2|BOOK2|I|2
LIB1|BOOK1|I|3
First i need sort the file based on LibraryName, BookName and Flag-Indicator and sum the book count value based on Flag value.
The end result should be saved in the called File2.txt.
Sorted File:
LIB1|BOOK1|A|12
LIB1|BOOK1|A|2
LIB1|BOOK1|I|22
LIB1|BOOK1|I|3
LIB1|BOOK1|I|4
LIB1|BOOK2|A|12
LIB1|BOOK2|I|2
LIB1|BOOK2|I|3
LIB1|BOOK2|I|8
LIB2|BOOK1|A|12
LIB2|BOOK1|A|2
LIB2|BOOK1|A|22
LIB2|BOOK1|I|4
LIB2|BOOK2|A|2
LIB2|BOOK2|I|1
LIB2|BOOK2|I|2
LIB2|BOOK2|I|3
Final File2.txt should look like this:
LibraryName|BookName|A-Flag-COUNT|I-Flag-COUNT
LIB1|BOOK1|14|29
LIB1|BOOK2|12|13
LIB2|BOOK1|36|4
LIB2|BOOK2|2|16
Thanks in advance for your help.
Thanks,
Venkat