State Change count in the column


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting State Change count in the column
# 1  
Old 08-12-2008
State Change count in the column

Dear all,
I have file like below shown. In that file i need to identify how many state change in the column "type".For example 94713357873 goes from type B --> 1
i need to count it.But when we count the x number should be uniq, cant get the count B-->1 state chage for different x numbers.

so the result should be

x number state charge count ( B ---> 1)
===== ===============
94713357873 1
94713358041 2

Please help me do this.


x number y number type
========== ========== =====
94713357873 20080811101444 B
94713357873 20080811114146 B
94713357873 20080811133403 B
94713357873 20080811133528 B
94713357873 20080811133823 B
94713357873 20080811133947 1
94713357873 20080811220606 B
94713357873 20080811222120 B
94713357877 20080811185438 1
94713357879 20080811084432 1
94713358033 20080811205622 2
94713358035 20080811130731 1
94713358041 20080810230925 B
94713358041 20080810234013 1
94713358041 20080811181138 1
94713358041 20080810230925 B
94713358041 20080810234013 1
94713358041 20080811181138 1

Thank you.
Nayanajith.
# 2  
Old 08-12-2008
Code:
#   awk '{if (t[$1]=="B" && $3==1){c[$1]+=1}t[$1]=$3}END{for (i in c) print i,c[i]}' file
94713358041 2
94713357873 1

# 3  
Old 08-12-2008
more generic:

Code:
#  nawk 's[$1] == $3 {next} s[$1] == 0 { s[$1] = $3 ;  next } { c[$1  " " s[$1] "->" $3]++ ; s[$1] = $3 } END { for (i in c) { print i "  cnt=" c[i] } }' file | sort
94713357873 1->B  cnt=1
94713357873 B->1  cnt=1
94713358041 1->B  cnt=1
94713358041 B->1  cnt=2

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Column 2 string count in Column 3

My I/p is Col1|Col2|Col3 2116209997932|POSIX INC|POSIX 2116209997933|POSIX INC|POSIX 2116210089479|POSIX INC|POSIX 2116210180502|POSIX INC|POSIX 2116210512279|POSIX INC|Aero 2116210516838|POSIX INC|POSIX 2116210534342|POSIX INC|postal 2116210534345|POSIX INC|postal ... (6 Replies)
Discussion started by: nikhil jain
6 Replies

2. Shell Programming and Scripting

Read first column and count lines in second column using awk

Hello all, I would like to ask your help here: I've a huge file that has 2 columns. A part of it is: sorted.txt: kss23 rml.67lkj kss23 zhh.6gf kss23 nhd.09.fdd kss23 hp.767.88.89 fl67 nmdsfs.56.df.67 fl67 kk.fgf.98.56.n fl67 bgdgdfg.hjj.879.d fl66 kl..hfh.76.ghg fl66... (5 Replies)
Discussion started by: Padavan
5 Replies

3. AIX

Open firmware state to running state

Hi Admins, I am having a whole system lpar in open firmware state on HMC. How can I bring it to running state ? Let me know. Thanks. (2 Replies)
Discussion started by: snchaudhari2
2 Replies

4. Shell Programming and Scripting

Count char, sum and change

Hello, I have some problem in counting char of word, sum and change. I'm not sure shell script can do this. Input data: Sam1 BB BB AA AA BB BB BB Sam2 BB BB AA AA AB AB AB Sam3 BB BB BB AA BB BB BB Sam4 AB AB AB AB AB AB AA Sam5 BB BB AA AA BB BB -- If I count in column 2, B is 9... (3 Replies)
Discussion started by: awil
3 Replies

5. Shell Programming and Scripting

Change column to row base on column 2

Hi Guys, Input.txt L194 A -118.2 L194 B -115.1 L194 C -118.7 L196 A 0 L196 C 0 L197 A -111.2 L197 B -118.9 L197 C -119.9 L199 A -120.4 L199 B -119.9 ... (2 Replies)
Discussion started by: asavaliya
2 Replies

6. Shell Programming and Scripting

awk or sed: change the color of a column w/o screwing up column spacing

Hey folks. I wrote a little awk script that summarizes /proc/net/dev info and then pipes it to the nix column command to set up column spacing appropriately. Here's some example output: Iface RxMBytes RxPackets RxErrs RxDrop TxMBytes TxPackets TxErrs TxDrop bond0 9 83830... (3 Replies)
Discussion started by: ryran
3 Replies

7. Shell Programming and Scripting

Change file content 4 column to one Column using script

Hi Gurus, I have file content sample: ,5113955056,,TAgent-Suspend ,5119418233,,TAgent-Suspend ,5102119078,,TAgent-Suspend filenames 120229H5_suspend, 120229H6_unsuspend I receive those files one of directory /home/temp/ I need following: 1. Backup first /home/temp/ file to... (5 Replies)
Discussion started by: thepurple
5 Replies

8. Shell Programming and Scripting

Change names in a column based on the symbols in another column

If the 4th column has - sign then the names in 3rd column has to change to some user defined names (as shown in output). Thanx input1 1 a aaaaa + 2 b bbbbb + 3 c ccccc + 4 d ddddd + 5 e eeeee + 6 f xxxxx + 8 h hhhhh +... (8 Replies)
Discussion started by: repinementer
8 Replies

9. UNIX for Advanced & Expert Users

need code to track the state change of wuftpd

i need to track the state changes of WUFTP daemon (FTP server)and to get the system calls executed at each state. WUFTpd statrts running at rootstate initially when a user logins it changes to that user state and then it again changes it state to root to make a socket connection to client. i need... (0 Replies)
Discussion started by: selvaraniantony
0 Replies
Login or Register to Ask a Question