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
PESCETTI(1)						      General Commands Manual						       PESCETTI(1)

NAME
pescetti -- Pseudo-Duplimate Generator SYNOPSIS
pescetti DESCRIPTION
This manual page documents briefly the pescetti command. OPTIONS
Here are a list of the available options and what they do. You must specify exactly one from --demo, --generate or --load. --help Prints the help text --demo Demonstration mode. Generates one hand with permutations and the tutorial for how to use them. --generate=N Generate N random boards --load=boards.txt Load boards+analysis from boards.txt --load-dds=boards.dds Load boards from boards.dds in dds format --load-analysis=tricks.txt Load analysis from tricks.txt --permutations=permutations.txt Generate the permutations and save them to the given file --curtains=curtains.txt Save curtain cards to file curtains.txt --save=boards.txt Save the boards+analysis to boards.txt --save-dds=boards.dds Save the boards to boards.dds in dds format --save-analysis=tricks.txt Save the analysis to tricks.txt --format=html|txt|pdf Set the output mode to the given format --title=title Set the title for the output --output=hands.txt Print the hands to hands.txt, rather than to standard output --stats Generate statistics about the set of boards; included in the hands output --analyze Run the dds analyzer on the boards and print the resulting numberof tricks (warning SLOW) --criteria= A list of criteria to apply to each generated hand to generate specific hand types. The list should be space separated and each item may be suffixed with a colon and a (fractional) probability value which can be used to weight the criteria. E.g. --criteria="weaknt:0.8 strongnt:0.5" Valid criteria are: unbalanced weaknt strongnt twont strongtwo weaktwo three twoclubs 4441 singlesuit twosuits partscore game slam game-invite slam-invite jumpshift jumpfit splinter bacon weird --probability=factor Generate hands matching the criteria with only the given probability. Factor is in the range 0 to 1. On each attempt to generate a board it is rejected if it doesn't match the criteria with the given probability. A factor of about 0.8 gives roughly half matching boards AUTHOR
This manual page was written by Matthew Johnson <debian@matthew.ath.cx>. Permission is granted to copy, distribute and/or modify this docu- ment under the terms of the GNU General Public License, Version 2 as published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL. PESCETTI(1)
All times are GMT -4. The time now is 09:26 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy