Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Add numbers in third code with conditions on the 1st and 2nd Post 302883318 by TheTransporter on Monday 13th of January 2014 09:48:05 AM
Old 01-13-2014
Hey admin,

Thanks for the interest.

I have written the following code that works, but it significantly slow.

calling ./counter.sh

Code:
#!/bin/bash
awk '{print $1}' $1 > 1.txt
awk '{print $2}' $1 > 2.txt
awk '{print $3}' $1 > 3.txt
paste 1.txt 2.txt | tr '\t' '_' > non-reverse.txt
paste 2.txt 1.txt | tr '\t' '_'> reverse.txt
paste non-reverse.txt 3.txt > tt; mv tt non-reverse.txt
paste reverse.txt 3.txt > tt; mv tt reverse.txt
cat reverse.txt non-reverse.txt > duplicates.txt
cat duplicates.txt | sort -nk1 | uniq > tt; mv tt duplicates.txt
awk '{print $1}' duplicates.txt | sort -nk1 | uniq > pair
for i in `cat pair`; do echo $i >> tt ; grep $i duplicates.txt | awk '{ sum+=$2} END {print sum}' >> tt; done
mv tt added_duplicates.txt
sed '$!N;s/\n/,/' added_duplicates.txt  | sort -nk1 | uniq > tt; mv tt final.txt
cat final.txt | tr '_' ' ' | tr ',' ' ' | grep ^[A-Z]  > tt; mv tt final.txt
rm -rf added_duplicates.txt non-reverse.txt reverse.txt duplicates.txt pair added_duplicates

 

We Also Found This Discussion For You

1. UNIX for Dummies Questions & Answers

Want the UNIX code - I want to sum of the 1st column wherever the first 2nd and 3rd columns r equal

I have the code for the below things.. File1 has the content as below 8859 0 subscriberCreate 18 0 subscriberPaymentMethodChange 1650 0 subscriberProfileUpdate 7668 0 subscriberStatusChange 13 4020100 subscriberProfileUpdate 1 4020129 subscriberStatusChange 2 4020307 subscriberCreate 8831... (5 Replies)
Discussion started by: Mahen
5 Replies
ATR_ANALYSIS(1p)                                                   User Commands                                                  ATR_ANALYSIS(1p)

NAME
ATR_analysis - analyse a smart card ATR SYNOPSIS
ATR_analysis [ATRstring] DESCRIPTION
ATR_analysis is used to parse the ATR (Answer To Reset) sent by a smart card. The command also tries to find the card model using an ATR database stored in a text file smartcard_list.txt. The smartcard_list.txt file is searched in ./, /usr/local/pcsc/ and /usr/share/pcsc/ directories. Exemple: $ ATR_analysis '3B A7 00 40 18 80 65 A2 08 01 01 52' ATR: 3B A7 00 40 18 80 65 A2 08 01 01 52 + TS = 3B --> Direct Convention + T0 = A7, Y(1): 1010, K: 7 (historical bytes) TB(1) = 00 --> Programming Param P: 0, I: 0 TD(1) = 40 --> Y(i+1) = 0100, Protocol T = 0 ----- TC(2) = 18 --> Work waiting time: 960 x 24 x (Fi/F) + Historical bytes: 80 65 A2 08 01 01 52 Possibly identified card: 3B A7 00 40 18 80 65 A2 08 01 01 52 Gemplus GPK8000 BUGS
Maybe many bugs since I am not a ISO 7816 expert. FILES
smartcard_list.txt SEE ALSO
pcscd(8), pcsc_scan(1) AUTHOR
Ludovic Rousseau <ludovic.rousseau@free.fr> Version: 1.3 October 2005 ATR_ANALYSIS(1p)
All times are GMT -4. The time now is 01:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy