Sponsored Content
Top Forums Shell Programming and Scripting Group on the basis of common text in the square bracket and sorting Post 302443540 by cdfd123 on Monday 9th of August 2010 07:22:26 AM
Old 08-09-2010
Java Group on the basis of common text in the square bracket and sorting

File A

Code:
99   >ac [John 2]  >ss[John 2] >juk[John 2]
70   >acb[Mona 3.1] >defa[Mona 3.1]
90   >ca[John 2]
100  >aa[John 2] >abc[John 2]  >bca[John 2]
85  >cde[Mona 3.1]
81 >ghi[Rambo] >ghij [Rambo]
87 >def[Mona 3.1] >fgh[Mona 3.1] <ijk [Mona 3.1]
89  >fck[Rambo] >ghij[Rambo] >kill[Rambo] >aa[Rambo]

Code:
The given output shud be 
100  >aa[John 2] >abc[John 2]  >bca[John 2]
87 >def[Mona 3.1] >fgh[Mona 3.1] <ijk [Mona 3.1]
89  >fck[Rambo] >ghij[Rambo] >kill[Rambo] >aa[Rambo]

On the basis of text common within the square brackets , we can group accordingly and take one which have highest number in each group.

How can be done ?
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Extract string in square bracket

Hi Input text is some message some message some message Expected output is main value1 value2 value3 Any idea how to above values in square brackets using shell scripting? many thanks. (3 Replies)
Discussion started by: hnh
3 Replies

2. Shell Programming and Scripting

sorting of files on the basis of timestamp

Hi, With the help of below script im able to get the count of all the .xml files but that count is not specific to a day ie its the total count of all .xml files what i want is specific to 1 day and that of every half an hr ie from 23 feb 2009 7 am till 23rd feb 2009 2300 am and from 07:00 to... (1 Reply)
Discussion started by: ss_ss
1 Replies

3. Shell Programming and Scripting

Expect Script square bracket dollar prompt

Hi Thanks for this amazing forum first, I've been searching answers in it for problems that I've encountered at work. The only problem I haven't been able to find a fix for, is a ever waiting for prompt problem in Expect when encounter a $ prompt. I usually set the timeout to -1 cause the... (2 Replies)
Discussion started by: Ikaro0
2 Replies

4. Shell Programming and Scripting

perl : merging two arrays on basis of common parameter

I have 2 arrays, @array1 contains records in the format 1|_|X|_|ssd|_| 4|_|H|_|hbd|_| 9|_|Y|_|u8gjdfg|_| @array2 contains records in the format X|_|asdf|_| Y|_|qwer|_| A|_|9kdkf|_| @array3 should contain records in the PLz X|_|ssd|_|asdf|_| Y|_|hdb|_|qwer|_| PLZ dont use... (2 Replies)
Discussion started by: centurion_13
2 Replies

5. Shell Programming and Scripting

Delete text between square brackets and also delete those square brackets using sed or awk

Hi All, I have a text file which looks like this: computer programming systems engineering I want to get rid of these square brackets and also the text that is inside these brackets. So that my final text file looks like this: computer programming systems engineering I am using... (3 Replies)
Discussion started by: shoaibjameel123
3 Replies

6. Shell Programming and Scripting

ksh, difference between double bracket and single bracket

Can somebody tell me the difference between double brackets and single brackets, when doing a test. I have always been acustomed to using single brackets and have not encountered any issues to date. Why would somebody use double brackets. Ie if ] vs if Thanks to... (2 Replies)
Discussion started by: BeefStu
2 Replies

7. Shell Programming and Scripting

Doubt with regex to replace square bracket

there is a word "welcome" output should be "welcome\ i am using regsub to add backslash "\" in place where ever i find square brackets (open or close).. But i am not getting it... pls help out.. set a {welcome} set d (5 Replies)
Discussion started by: Syed Imran
5 Replies

8. UNIX for Dummies Questions & Answers

Plz Help in sorting the data on date basis

I have file having below data 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493 01-JUL-13... (2 Replies)
Discussion started by: ranabhavish
2 Replies

9. Shell Programming and Scripting

Plz Help in sorting the data on date basis

I have file a.txt having below data cat a.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 IN 1514 0000764631 01-NOV-13 2.38.11.00.100089 IN 1514 0000856571 01-NOV-13 2.38.15.00.100015 IN 300.32 0000856531 01-JUN-13 2.38.19.00.100000 IN 2698 0000764493... (5 Replies)
Discussion started by: ranabhavish
5 Replies

10. Shell Programming and Scripting

Sorting on date basis

I have file data.txt having below data cat data.txt 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-MAY-13 2.38.11.00.100089 IN 4512 0000741881 01-JUN-13 2.38.11.00.100089 FC 1514 0000764631 01-NOV-13 2.38.11.00.100089 FC 1514 0000856571 01-NOV-13 2.38.11.00.100089 IN 300.32... (1 Reply)
Discussion started by: ranabhavish
1 Replies
UKSORT(3)								 1								 UKSORT(3)

uksort - Sort an array by keys using a user-defined comparison function

SYNOPSIS
bool uksort (array &$array, callable $key_compare_func) DESCRIPTION
uksort(3) will sort the keys of an array using a user-supplied comparison function. If the array you wish to sort needs to be sorted by some non-trivial criteria, you should use this function. PARAMETERS
o $array - The input array. o $key_compare_func - The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. int callback (mixed $a, mixed $b) RETURN VALUES
Returns TRUE on success or FALSE on failure. EXAMPLES
Example #1 uksort(3) example <?php function cmp($a, $b) { $a = preg_replace('@^(a|an|the) @', '', $a); $b = preg_replace('@^(a|an|the) @', '', $b); return strcasecmp($a, $b); } $a = array("John" => 1, "the Earth" => 2, "an apple" => 3, "a banana" => 4); uksort($a, "cmp"); foreach ($a as $key => $value) { echo "$key: $value "; } ?> The above example will output: an apple: 3 a banana: 4 the Earth: 2 John: 1 SEE ALSO
usort(3), The comparison of array sorting functions. PHP Documentation Group UKSORT(3)
All times are GMT -4. The time now is 09:55 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy