Simpler Navigation for Servers and Operating Systems
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
cancel
Showing results for 
Search instead for 
Did you mean: 

help in sorting a file

SOLVED
Go to solution
lawrenzo_1
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
lawrenzo_1
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
H.Merijn Brand (procura
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
Ninad_1
Honored Contributor
Solution

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
lawrenzo_1
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
H.Merijn Brand (procura
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
Highlighted
lawrenzo_1
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