Re: help in sorting a file (158 Views)
Reply
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 1 of 7 (158 Views)
Accepted Solution

help in sorting a file

Hi,

I have a large file which process's many accounts, I need to search and grep out information between 2 lines ie:

S9 transactions started

23450 row(s) unloaded

S9 Transactions finished

T4 Transactions started

32475 row(s) unloaded

T4 Transactions finished

so in this case I want the amount of rows unloaded for S9 transactions.

any ideas?

Thanks
hello
Please use plain text.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 2 of 7 (158 Views)

Re: help in sorting a file

I'd also like to add to this that after S9 transactions started there is also a date field I'd like to display with the rows on the below line also detailed so ie

S9 Transactions started 23450


Thanks in advance
hello
Please use plain text.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,185
Registered: ‎10-13-1997
Message 3 of 7 (158 Views)

Re: help in sorting a file

lt09:/tmp 107 > cat test.dta
S9 transactions started

23450 row(s) unloaded

S9 Transactions finished

T4 Transactions started

32475 row(s) unloaded

T4 Transactions finished
lt09:/tmp 108 > perl -e'$/="finished\n";$p=shift;while(<>){/$p/s and print}' S9 test.dta
S9 transactions started

23450 row(s) unloaded

S9 Transactions finished
lt09:/tmp 109 >

Does that give you enough rope to tie the problem down?

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Please use plain text.
Honored Contributor
Ninad_1
Posts: 990
Registered: ‎05-22-2002
Message 4 of 7 (158 Views)

Re: help in sorting a file

One more way,
echo "S9 Transactions started $(date) $(awk '/S9 transactions started/,/S9 Transactions finished/' filename | grep unloaded | awk '{print $1}')"

Regards,
Ninad
Please use plain text.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 5 of 7 (158 Views)

Re: help in sorting a file

thanks guys, because I am not familiar with perl i used the second method however P please post a reply here and I will give you more points as I inserted 2 by mistake, which I believe is incorrect because your method does work.

Thanks guys.
hello
Please use plain text.
Honored Contributor
H.Merijn Brand (procura
Posts: 6,185
Registered: ‎10-13-1997
Message 6 of 7 (158 Views)

Re: help in sorting a file

Thanks for being openminded to my world of Perl :)

Enjoy, Have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
Please use plain text.
Super Advisor
lawrenzo_1
Posts: 560
Registered: ‎06-06-2003
Message 7 of 7 (158 Views)

Re: help in sorting a file

Thanks Procura, maybe look into perl once I mastered awk and sed lol.

Have a great day!

8)
hello
Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation