Languages and Scripting
Showing results for 
Search instead for 
Do you mean 

help in sorting a file

SOLVED
Go to Solution
Super Advisor Super Advisor

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
6 REPLIES
Super Advisor Super Advisor

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
Honored Contributor Honored Contributor

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
Highlighted
Honored Contributor

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
Super Advisor Super Advisor

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
Honored Contributor Honored Contributor

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
Super Advisor Super Advisor

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