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
GIT-COLUMN(1)							    Git Manual							     GIT-COLUMN(1)

NAME
git-column - Display data in columns SYNOPSIS
git column [--command=<name>] [--[raw-]mode=<mode>] [--width=<width>] [--indent=<string>] [--nl=<string>] [--padding=<n>] DESCRIPTION
This command formats its input into multiple columns. OPTIONS
--command=<name> Look up layout mode using configuration variable column.<name> and column.ui. --mode=<mode> Specify layout mode. See configuration variable column.ui for option syntax. --raw-mode=<n> Same as --mode but take mode encoded as a number. This is mainly used by other commands that have already parsed layout mode. --width=<width> Specify the terminal width. By default git column will detect the terminal width, or fall back to 80 if it is unable to do so. --indent=<string> String to be printed at the beginning of each line. --nl=<N> String to be printed at the end of each line, including newline character. --padding=<N> The number of spaces between columns. One space by default. AUTHOR
Written by Nguyen Thai Ngoc Duy <pclouds@gmail.com[1]> GIT
Part of the git(1) suite NOTES
1. pclouds@gmail.com mailto:pclouds@gmail.com Git 1.8.3.1 06/10/2014 GIT-COLUMN(1)
All times are GMT -4. The time now is 07:46 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy